Wednesday, 15 July 2015

Using cookies to filter data in Google Analytics -



Using cookies to filter data in Google Analytics -

i trying filter google analytics info company site based on cookie. don't want track internal traffic, can't filter based on ip address range because there internal users want still track. have pretty simple code adding cookie, not sure add together code. new cookies, , couldn't find online clear on how add together or utilize cookie.

<html> <head> <title>remove internal traffic google analytics</title> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setaccount', 'ua-xxxxx-yy']); _gaq.push(['_setvar','employee']); _gaq.push(['_trackpageview']); (function() { var ga = document.createelement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : http://www') + '.google-analytics.com/ga.js'; var s = document.getelementsbytagname('script')[0]; s.parentnode.insertbefore(ga, s); })();

so question is, code go? helping out novice skills cookies.

do not utilize setvar (this deprecated), utilize _setcustomvar:

_setcustomvar(index, name, value, opt_scope)

the phone call goes before _trackpageview call.

there 5 custom vars in standard ga (50 in premium), that's "index". 'name' , 'value' should clear.

customvars either valid current page, session or visitor (in lastly case valid until visitors clears cookies in browsers unless waits 6 months before visits site again).

like every instruction asynonchronous ga code "pushed" on gaq-array, right phone call be:

_gaq.push(['_setcustomvar', 1, // custom var set slot #1. required parameter. 'items removed', // name acts kind of category user activity. required parameter. 'yes', // value of custom variable. required parameter. 2 // sets scope session-level. optional parameter. ]);

which taken google documentation here: https://developers.google.com/analytics/devguides/collection/gajs/gatrackingcustomvariables#setup.

i still maintain utilize case opt-out plugin improve solution.

update: thinking don't think need setcustomvar or custom cookies @ all. have employees go website via link like:

mywebsite.com?utm_source=allyourbasearebelongtous

then go profile settings , create custom filter, set exclude, filter field "campaign source" , filter pattern "allyourbasearebelongtous" (or whatever name gave campaign parameter).

this uses cookie (the standard google cookie) not need custom code @ all. campaign source parameter valid until visit campaign geared towards site, if wants test ga code need delete cookies or utilize incognito mode (but that't not different setting custom cookie or setcustomvar-methods).

cookies google-analytics

No comments:

Post a Comment