views:

61

answers:

2

Hi,

Could anyone clarify how the GA actions _gaq.push(['_link', <href>]); and _gaq.push(['_linkByPost', <form>]); work?

I'm not interested on how to use them as presented in the documentation. I understand those scenarios. I want to know more about what they do when called.

Edit:

I suspect how this works but I need some confirmation from someone that fiddled with this longer than me. I want to know what the process is in each of the cases in small steps. I know that it changes the sent data in order to overwrite to cookie on the target site, but I need to know exactly the actions that happen (in terms of JavaScript on the sending page) after you do the push.

I would also like to know if I could use _gaq.push(['_link', <href>]); from anywhere in my code to change the page.

Thank you, Alin

A: 

They pass the cookie information from one domain to another; in the instance, it does this by appending a query string on the next page; with _linkByPost, it sends the cookie information as a POST along with your POST data.

If _setAllowLinker is set to true on the target page, the cookie information sent will overwrite the default Google Analytics cookies on the target page, and will allow for linked, consistent session information between the two, as the cookies will ensure that consistent data is shared.

EDIT:

No, you can't call it from anywhere in your page, unless you bind it to an onclick of where you'd like it called.

yc
Thank you for your effort but it doesn't offer me any new information. Also I tried _linkByPost and it appends the GA params to the URL of my POST so practically they are in the GET.
Alin Purcaru
A: 

We will assume _gaq.push(['_setAllowLinker', true]); used on any needed page.

What _gaq.push(['_link', <href>]); does:

  1. Appends the __utm<x> cookies to <href>. You need to return false in the onclick of the anchor so that the original link does not follow through.
  2. Changes the browser location to the newly formed URL.

What _gaq.push(['_linkByPost', <form>]); does:

  1. Changes the action attribute of <form> so that it includes the __utm<x> cookies.

What happens on the target page:

  1. The GA script on the target page checks the received parameters and if the __utm<x>s are sent it overwrites its own cookies with these. This results in identifying the user as being the same on that left your original page.

As a bonus _gaq.push(['_link', <href>]); can be used in (almost) any situation window.open(<href>); can be used.

Alin Purcaru