Hi,
I was looking for a way to explicitly specify a event tracking code for links in my website.
So far, the best I got is adding a rel="ga|...|" to my links.
For instance, if I want to track a specific link, I will do like this
<a href="#" rel="ga|Download|Brochure|Inbound Marketing">Lien test</a>
The code I added in the googleanalytics.js file was the following one:
if ($(this).attr('rel') !== undefined && $(this).attr('rel').substring(0, 2) == 'ga') {
opts = $(this).attr('rel').split('|');
if (opts[1] !== undefined) category = opts[1]; else category = 'Default Category';
if (opts[2] !== undefined) action = opts[2]; else action = 'Default Action';
if (opts[3] !== undefined) label = opts[3]; else label = '';
if (opts[4] !== undefined) value = parseInt(opts[4]); else value = 0;
if (opts[5] !== undefined) nonInteraction = opts[5]; else nonInteraction = false;
_gaq.push(["_trackEvent", category, action, label, value, nonInteraction]);
}
It works good for what I want to do but I just wanted to share my solution with the community to get feedback and maybe a cleaner solution could be implemented in later versions.
Thanks for the great work in any case !
(You can find the full js file in attachment)
Comment | File | Size | Author |
---|---|---|---|
googleanalytics.txt | 4.19 KB | Emile Fyon |
Comments
Comment #1
hass CreditAttribution: hass commentedInterresting...
You may look for #1833578: Add support Enhanced Link Attribution
Comment #2
hass CreditAttribution: hass commented