Google UTM Campaign Tracking in AMP amp-analytics

433 views Asked by At

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.

1

There are 1 answers

0
Bill Zheng On

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"}}}}, e.g. 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.