How to cross direct user using Google Analytics

After the user fills out my “new” user form on “example-one.com”, the “create” controller creates an entry in db. He then redirects_to to the external site "payment-checkout.com". I installed the Google Analytics code on both sites.

Google provides two _link and _linkByPost functions for use in any links or forms that go to your external domains. The problem is that the user is being redirected by the controller action outside the view, and I cannot use these two javascript functions to convey the relevant GA info - what am I doing?

Can anyone help?

+7
source share
3 answers

The _link method is to transfer Google Analytics cookies from your first domain using the query string to the second domain. The second domain, if configured correctly, will accept these URL parameters and use them as cookie values ​​for tracking purposes.

So, it’s easy for you to use your own version of the _link function.

In particular, the _link function transmits the following cookies:

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

To the 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 server-side redirection, grab the cookie values ​​and apply them as a query string in the URL you are redirecting to.

Now, this is not the only thing you need to do to make it work. The configuration of Google Analytics on the payment site should be configured with the _setAllowLinker parameter _setAllowLinker to true, and also potentially disable the domain hash and set a specific domain name for tracking files; it depends on your configuration. For more information, see the Google Analytics Cross-Domain Tracking Guide .

+3
source
An approach

@yc looks like the best option, but if that doesn't work, I would suggest that your controller redirect the user to the "temp" page on your site and show some text, for example, "Check out out". Wait ... "and using Javascript will activate the call to the" _link "function to redirect the user to" payment-checkout.com "(again using Javascript).

+1
source

I assume that you are also tracking the page that the user is returning to and want to measure how many users you lose in the process between them?

My knowledge of the Google Analytics API is quite limited, so there may be a better solution, but can you think of making a page containing GA code and running the _link () function from there?

It is also possible to make an AJAX call when submitting the form (possibly using remote_form_for) and handle the GA redirection in the RJS response:

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

However, I'm not sure how well this will fit into your application.

0
source