[英]Google UTM Campaign Tracking in AMP amp-analytics
I am building an AMP website, and I use google analytics for tracking.我正在建立一个 AMP 网站,并使用谷歌分析进行跟踪。 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.但是,当我将网站迁移到 AMP 时,我发现
utm_campaign
、 utm_source
和utm_medium
属性不起作用,而当我使用 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.我试图在 url 的末尾添加
?utm_source=some_value&utm_campaign=some_value&utm_medium=some_value
,它不起作用。 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.我尝试通过
amp-analytics
配置中的extraUrlParams
添加这些值,如下所示: "extraUrlParams": {"utm_source": "test", "utm_campaign": "test", "utm_medium": "test"}
也不行。
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.当请求带有
?utm_campaign=some_value&utm_medium=some_value&utm_source=some_value
时,它可能不是amp-analytics
发送到 GA 的实际链接。 Actually it is sending the page_location
in the amp-analytics
configuration.实际上它是在
amp-analytics
配置中发送page_location
。
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.所以如果你的配置是这样的:
{"vars": {"gtag_id":"UA-XXXX-0", "config": {"UA-XXXX-0": {"page_title":"some_value","page_location":"$urlWithParams"}}}}
,例如当前页面位置是https://example.com/ ,那么page_location
应该像https://example.com/?utm_campaign=some_value&utm_source=some_value ,然后它将捕获 UTM 值。 To achieve this, you can either get the current window location or url params using AMP url variables.为此,您可以使用 AMP url 变量获取当前 window 位置或 url 参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.