简体   繁体   中英

Google UTM Campaign Tracking in AMP amp-analytics

I am building an AMP website, and I use google analytics for tracking. However I found the utm_campaign , utm_source and utm_medium properties are not working when I migrate my site to AMP, it was working when I was using analytics.js. I tried to add ?utm_source=some_value&utm_campaign=some_value&utm_medium=some_value at the end of url, it doesn't work. I tried to add these values through extraUrlParams in the amp-analytics configuration like this: "extraUrlParams": {"utm_source": "test", "utm_campaign": "test", "utm_medium": "test"} , it doesn't work as well.

After some further digging, this problem solved. Here is how to solve the issue.

When a request comes in with ?utm_campaign=some_value&utm_medium=some_value&utm_source=some_value , it probably not the actual link amp-analytics send to GA. Actually it is sending the page_location in the amp-analytics configuration.

So if your configuration is like this: {"vars": {"gtag_id":"UA-XXXX-0", "config": {"UA-XXXX-0": {"page_title":"some_value","page_location":"$urlWithParams"}}}} , eg current page location is https://example.com/ , then the page_location should be like https://example.com/?utm_campaign=some_value&utm_source=some_value&utm_medium=some_value , then it will capture the UTM values. To achieve this, you can either get the current window location or url params using AMP url variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM