开发者

What is the correct syntax for adding a custom cookie in Google Analytics?

开发者 https://www.devze.com 2023-02-09 15:25 出处:网络
Google\'s own site seems to provide conflicting documentation. I\'ve found at least 4 variations for adding A custom cookie to GA.

Google's own site seems to provide conflicting documentation.

I've found at least 4 variations for adding A custom cookie to GA.

http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=6a452bd09455721a&hl=en

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html

http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=4362f4d46e6e723a&hl=en

http://analytics.blogspot.com/2009/07/segment-your-traffic-with-user-defined.html

Here is the code I currently have embedded in my company's sharepoint site. I'm beginning to think that this will not work, and that I will have to create an "employee.html" page on my public webserver that I will have to request all employees load once to generate the cookie on their PC's. My secondary question, is after I setup a employee.html page as the example http://analytics.blogspot.com/2009/07/segment-your-traffic-with-user-defined.html here describes, how do I keep a开发者_运维问答ll the external traffic from accessing that same page?

    <script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-20842347-1']);
    _gaq.push(['_setCustomVar',1,'visitor-type','employee']);   
    _gaq.push(['_setDomainName', '.sc-pa.com']);
    _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);
    })();

</script>   
</HEAD>


None of those links talk about setting a custom cookie. Also, it seems to me that you aren't really needing to set a custom cookie. It looks like you are just wanting to be able to segment your traffic into different buckets.

You can do this many different ways, one of which you have in your code example: you can set a custom variable with different values, depending on the type of user.

So it would set the same cookie, etc.. and you pass different values in this line of code

_gaq.push(['_setCustomVar',1,'visitor-type','employee']); 

Then in your reports you can setup filters based off of custom variable 1, or look at the custom variable reports directory, or use custom variable 1 as a metric in your reports.

0

精彩评论

暂无评论...
验证码 换一张
取 消