There is actually 2 ways you can do it:
- An easier and straightforward one
- Advanced using Google Analytics API and custom integration
Content
1. Track leads with AC form and GTM code (20 min)
Requirements:
- AC form
- Landing page
- GTM
Update form with source value code – https://www.codepile.net/pile/oRzY1mAM
Steps to implement source tracking
- Create custom fields in AC for Source / Medium data
- Add form with hidden fields to website / landing page
- Setup GTM variables which extract ute tags from url parameter
- Create url with utm tags – https://ga-dev-tools.appspot.com/campaign-url-builder/
- 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
Feel free to leave your questions here or ping me directly via messenger
Hey Maksym,
This is great, thanks for laying it out so clearly!
I have an issue with the jQuery that adds it to the form. In my case I don’t want to / can’t use appendTo, but rather want to change the value of a hidden field that already exists. It has the ID “form-field-client_id”, but whatever I try the jQuery “val” doesn’t add the value via tag manager. Would be grateful for any advice.
Cheers,
Phil
Hello, awsome job!
I did all the steps but the client id does not go to the active campaign.
Do I need to modify this ‘form’ inside (jQuery (‘form’));?
jQuery (”) .appendTo (jQuery (‘form ‘));
The active campaign client id custom field is text line or hidden field?
Thankyou Very much