: Can you track one user's session with Google Analytics by using the __utma cookie's value? In Google Analytics, there is a cookie that stores a user's information that helps Google distinguish
In Google Analytics, there is a cookie that stores a user's information that helps Google distinguish new users from existing visitors (__utma). If I were to get that information from a user's cookie, is there any way to use that information to view that particular user's interactions with my site? At this point I'm considering just using a custom variable to store that cookie's value, and go from there, but since that cookie already exists, and Google obviously uses it, do they share any of that data to help re-create a user's session (to some limited extent)?
More posts by @Eichhorn148
1 Comments
Sorted by latest first Latest Oldest Best
Yes you can, this is the code I use, it may not be the neatest, so someone maybe able to clean it up. I have used a custom variable and believe this is the best solution.
It will only track this information after the first pageview as the cookie will not be set until then. There are workarounds such as triggering blank events so that the tracking works with all users, however this was enough for me, as if someone only visits one page, then you probably won't need to segment their data.
//Set Custom Var 1 - Visitor ID
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
var utma=getCookie("__utma");
if (utma == null) {var utma="000.999";}
var visitorID=utma.split(".");
//alert("visitor ID = " + visitorID[1]);
//GA Legacy Code
var _gaq = _gaq || [];
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'YOUR UA NUMBER']);
_gaq.push(['_setDomainName', 'YOUR DOMAIN']);
_gaq.push(['_setAllowLinker', true]);
if (visitorID[1] != "999") {_gaq.push(['_setCustomVar',1,'VisitorID',visitorID[1],1]);}//Send Custom Var 1
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
addLinkerEvents();
})();
It is important you don't import personally identifiable information as this would breach Google Analytics TOS.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.