There is actually 2 ways you can do it:

  1. An easier and straightforward one
  2. Advanced using Google Analytics API and custom integration

Content

1. Track leads with AC form and GTM code (20 min)

Requirements:

  1. AC form
  2. Landing page
  3. GTM

Update form with source value codehttps://www.codepile.net/pile/oRzY1mAM

Steps to implement source tracking

  1. Create custom fields in AC for Source / Medium data
  2. Add form with hidden fields to website / landing page
  3. Setup GTM variables which extract ute tags from url parameter
  4. Create url with utm tags – https://ga-dev-tools.appspot.com/campaign-url-builder/
  5. Add GTM tag which update hidden fields with traffic source value

2. [Advanced] Track leads using Google Analytics API and Integromat

1. Pass Client ID to Activecampaign (12 min)

Get Client ID code

function()
{
    var match = document.cookie.match('(?:^|;)\\s*_ga=([^;]*)');
    var raw = (match) ? decodeURIComponent(match[1]) : null;
if (raw)
{
match = raw.match(/(\d+\.\d+)$/);
}
var gacid = (match) ? match[1] : null;
if (gacid)
{
    return gacid;
}
}

https://www.codepile.net/pile/5YjoBkDR

Update form with client ID value 

<script>
  jQuery( '<input id="field[12]" type="hidden" name="field[12]" value="'+{{Client ID}}+'">' ).appendTo( jQuery( 'form' ) );
</script>

// replace field[12] with your custom field id

https://www.codepile.net/pile/5gwawrVl

2. Test Google Analytics API (3 min)

API reference – https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/userActivity/search

3. AC automation (8 min)

You can register Integromat here (if you haven’t yet)

4. Authorize Integromat to get info from Google API (17 min)

Test Google Analytics  API: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/userActivity/search

Interomat Google auth doc: https://support.integromat.com/hc/en-us/articles/360008096679-Calling-Google-APIs-via-the-HTTP-Make-a-OAuth-2-0-request-module

GA scope: https://www.googleapis.com/auth/analytics

5. Completion of Integromat scenario (11 min)

{
"viewId": "yourid",
"user": {
"userId": "{{2.contact.fields.client_id}}"
},
"activityTypes": [
"PAGEVIEW"
],
"dateRange": {
"startDate": "{{formatDate(addDays(now; -30); "YYYY-MM-DD")}}",
"endDate": "{{formatDate(now; "YYYY-MM-DD")}}"
}
}
//replace "viewID" with your GA view ID
// I've used here date range for last 30 days, make sure to change it if you need another date range

6. Test whole integration and summary

…to be uploaded