开发者

how to cross direct user with google analytics

开发者 https://www.devze.com 2023-02-10 20:37 出处:网络
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 ha

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 con开发者_JAVA百科troller action outside of the view and I cant use those two javascript functions to pass on the relevent G.A. 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's approach looks like the best bet but if that doesn't work, I would suggest having your controller redirect the user to a "temp" page on your site itself and show some text like "Checking out....Please wait..." and using Javascript trigger the call to the "_link" function to redirect the user to the "payment-checkout.com" (again using 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消