Google Analytics Cross Domain Tracking does not work

邮差的信 提交于 2019-12-13 21:33:49

问题


When a visitor tries to do a booking, the site directs him/her to the booking engine site.

ga('create', 'UA-XXXXXXXX-Y', 'auto', {'allowLinker': true });

ga('require', 'linker');

ga('linker:autoLink', ['mysite.com', 'bookingengine.com'], true, true);

ga('require', 'displayfeatures');

ga('require', 'linkid');

ga('send', 'pageview');

There are no errors or warnings.

I used a cookie monitor and it shows that browser creates another new _ga cookie when it loads the booking engine site. The same cookie ID is not used.

I was struggling for days changing code to ga('linker:autoLink', ['mysite.com', 'bookingengine.com'], false, true); but it did not work.


回答1:


Okay, I see the problem. If you fill in the form on your main site and click you see the _ga parameter is not appended to the url that calls the booking-engine. Since the parameter is necessary to transfer the clientid to the other site, where it is picked up by GA and used as clientid, cross-domain tracking cannot work - the GA code on the booking-engine does not find a _ga parameter in the incoming url and so starts a new sessions.

Usually the autolink plugin would add the parameter to the forms action. This does not work in your case since the form is actually submitted via a JQuery function (bookNow() in your functions.js file). This prevents the linker function from intercepting the submit event and adding the parameter.

The solution would be to add it yourself - get the linker parameter from the tracker object (tracker.get('linkerparam')) and add it to the form action and add it to the redirect url in the booknow() function.



来源:https://stackoverflow.com/questions/37538027/google-analytics-cross-domain-tracking-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!