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
Hi Phil, can you sand me link to your page with form to [email protected] so I could check if it is still actually for you?
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
Hi Thales, can you sand me your page with form to [email protected] so I could check if it is still actually for you?
(sorry for late reply)
Great post, thanks Maksym!
Everything worked for me. I used it to track my affiliation ID’s
HI Babast,
Glat to hear it helped you!
Hey Maks,
thanks a lot for your guide! It really helped! 🙂
As I am using Active Campaign’s API (not the original form snippet) and a different page builder I couldn’t make it work with your jQuery script :/
However I found a way to solve it with JavaScript (I’m also more familiar with JS than I am with jQuery)
In case this might be helpful for anyone else, here is the line of code, that I excecuted with GTM.
document.getElementById(‘fieldID-36576’).value={{UTMSource}};
Thanks Maria, it’s really helpfull
Hi,
I followed the steps and can see everything is showing up in the preview but the form data is not being transferred and saved in Active Campaign. Would you be able to help with a quick review sometime? I would greatly appreciate it.
Thanks!