创建后更改google-analytics TrackingId [英] Change google-analytics TrackingId after creating it
问题描述
描述:
我有一个使用googleanalytics代码的单页应用程序。该应用程序适用于4个不同的国家顶级域名,例如www.example.de,www.example.at,www.example.be等。也可以在不更改域名的情况下更改国家/地区。例如,如果您在域名www.example.co.uk上工作,则可以将国家更改为德国,而无需重新加载页面。
问题:
我需要为每个国家使用不同的trackingID,无需重新加载页面。
如果我使用.co.uk加载页面的域名跟踪ID。我不能在没有重新加载页面的情况下更改它。这怎么可能?
我阅读
奖金追踪,使用GTM:使用Google跟踪代码管理器和dataLayer您可以设置 在每一次击中的国家。你可以创建一个例如Vlookup Table Description: I have a singlepage application where I use googleanalytics code. The application is working for 4 different country top level domains e.g. www.example.de, www.example.at, www.example.be etc.. It is also possible to change the country without change the domain name. For example if you are working unter the domain www.example.co.uk you can change the country to germany without reloading the page. Problem: I need to use different trackingID for each country without reloading the page. If i load the page with .co.uk toplevel domain tracking id. I can not later change it without reloading the page. How is that possible? I read How Analytics Works document from google. And used Creating Trackers document to create the tracking code. Is it possible to change tracking ID after creating it ? Wow, this is very interesting. But it can be risky to take action without know that technology works. Maybe you need to do a Crossdomain for example. to have the same id on both account. But I will try to keep it simple: Yes, it's possible executing the command create, to do this when the user reach you domain track the the regular tracking code But when the user changes the language or country code you have to create a new
tracking object (after the new URL is on the broswer). So, on the SPA you have you push the Pageviews manually, with the command or Bonus track, Use GTM: With the Google Tag Manager and the dataLayer you can set the country on every hit. You can create for example a Vlookup Table For example, change the UA for the variable that read your value of the country on the dataLayer.push and return the needed UA on the Tags. It's the best way. But this answers is getting unnecessary long. Read more information
https://developers.google.com/tag-manager/quickstart 这篇关于创建后更改google-analytics TrackingId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
dataLayer.push({'country':'xxxx'})
<例如,更改dataLayer.push中读取国家/地区值的变量的UA,然后在标记上返回所需的UA。这是最好的方式。但是这个答案越来越没有必要。阅读更多信息
https://developers.google.com/tag-manager/quickstart <!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
ga('create', 'UA-XXXXX-Y', 'auto', 'trackercountryXX');
ga('send', 'pageview'); //to you original loaded tracking code
ga('trackercountryXX.send', 'pageview'); //If the interaction goes to the new tracking code.
dataLayer.push({'country' : 'xxxx'})