Google Analytics and Colorbox - Cross domain tracking

[亡魂溺海] 提交于 2019-12-08 11:56:32

问题


With our GA code, we are tracking multiple domains and subdomains, and we have the main bulk of the code tracking properly with only a couple of self-referrals. The biggest issue revolves around the fact that we use Colorbox for modal windows, and I need to be able to attach code to these pages to eliminate self referrals.

I've done a lot of searching, and working around in JavaScript to find a work-around, with no luck.

If I add onClick="_gaq.push(['_link', $(this).attr('href')]);return false;" to the a tag to open the modal window, when the page refreshes with the attach querystring params from Google, it breaks out of the modal window and takes over the entire browser window. I've tried building a custom function rather than just a straight onclick, and I get the same result. The only reference I have found is this article from 2010.

I'm at a loss here. I was thinking maybe I could grab the utmcc info pre-link and append it to the URL ahead of time, with no luck on finding a way to grab that from the session.


回答1:


This is the code I ended up using, thanks to yahelc for the help.

$('.link-btn').bind("cbox_complete", function(){
    var pageTracker = _gat._getTrackerByName();
    var href = $.colorbox.element().attr('href');
    if (href) {
        _gaq.push(function() {
          var pageTracker = _gat._getTrackerByName();
            setTimeout(function(){
                $('#cboxLoadedContent iframe').attr('src',pageTracker._getLinkerUrl(href));
            },1000);
        });
    }
});    



回答2:


_link is a convenience wrapper over _getLinkerUrl.

You can just convert the URL to have the linker dynamically in JavaScript without using the convenience function (which in this case is inconvenient). (Assuming jQuery, since you're using colorbox).

Assuming the markup on that link is something like <a href="..." class="colorboxlink">Click!</a>...

   $(".colorboxlink").each(function(){
        $(this).attr('href', function(i,v){
                 return _gat._getTrackerByName()._getLinkerUrl(v);
         });
   });

I'd only recommend this approach if it's no more than 1 or 2 links; for a large number of links (20+), it can have performance impacts. Here's a demo: http://jsfiddle.net/XscWT/



来源:https://stackoverflow.com/questions/8932016/google-analytics-and-colorbox-cross-domain-tracking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!