how to cross direct user with google analytics

After a user fills in my "new" user form on "example-one.com", the "create" controller creates the record in the db. Then it does a redirect_to to an external site "payment-checkout.com". I have setup the Google Analytics code on both sites.

Google provides two functions _link and _linkByPost for use to use in any links or forms that go to your external domains. The problem is the user is being redirected by the controller action outside of the view and I cant use those two javascript functions to pass on the relevent GA info - what do i do?

Can anyone help?


The way _link works is by passing the Google Analytics cookies from your first domain via a query string to your second domain. The second domain, if configured correctly, will accept those URL parameters and apply them as cookie values for the purposes of tracking.

So, it shouldn't be difficult for you to apply your own version of the _link function.

Specifically, the _link function passes the following cookies:

__utma , __utmb , __utmc , __utmx , __utmz , __utmv and __utmk

Into a query string as such: ?__utma=87278922.614105561.1288923931.1294376393.1298325957.6&__utmb=87278922.1.10.1298325957&__utmc=87278922&__utmx=-&__utmz=87278922.1288923931.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)&__utmv=-&__utmk=72493274

So, all you need to do to replicate the _link function is, before you apply the server side redirect, grab the cookie values, and apply them as a query string on the URL you're redirecting to.

Now, that's not the only thing you'll need to do to get this working. The Google Analytics configuration on the payment site will need to be configured with _setAllowLinker set to true, as well as potentially disabling the domain hash and setting a particular domain name for the tracking cookies; it depends on your configuration. You can find out more about that in Google Analytics Cross Domain Tracking Guide.


@ yc的方法看起来像是最好的选择,但如果这样做不起作用,我会建议让您的控制器将用户重定向到您网站上的“临时”页面,并显示一些文字,如“正在检出....请稍候。 ..“并且使用Javascript触发对”_link“函数的调用,以将用户重定向到”payment-checkout.com“(再次使用Javascript)。


I assume you're also tracking the page the user returns to and want to measure how many users you lose in the process in between?

My knowledge of the Google Analytics API is fairly limited, so maybe there's a better solution, but you could consider rendering a page containing the GA code and triggering the _link() function from there?

It might also be possible to perform an AJAX call on submitting the form (maybe using remote_form_for) and handling the GA redirect in an RJS-response:

page << "_gaq.push(['_link', 'http://example.com/test.html']);"

However, I'm not sure how well that would fit into your application.

链接地址: http://www.djcxy.com/p/50836.html

上一篇: 返回一个值

下一篇: 如何使直接用户与谷歌分析