English 中文(简体)
种族状况和使用谷歌分析仪
原标题:Race condition and using Google Analytics Asynchronous (_gaq) synchronously

我有一个网站,正在使用谷歌分析新器的同步跟踪方法(_gaq)。 我提出的问题是,我想进行一些具体的联系跟踪,担心我会创造种族条件。

基本上,它有一个新闻网站,因此它有一条连接各地报道的头条新闻。 一个故事的头线可能出现在一页的3个不同地点,并出现在数百个其他网页上。 因此,为了了解我们的受众是如何与网站互动的,我们必须追踪如何使用每个具体标题块,而不仅仅是目的地。 由于这两项规定追踪各页,或跟踪已点的网页,我们必须跟踪各个链接。

因此,如果我有联系的话。

<a href="http://www.blah.com" onclick="_gaq.push( _trackEvent , stuff )">Here</a>

由于_gaq.push()是一种不寻常的电话,因此,在谷歌点跟踪完成之前,页数的变化是可能的? 如果是这样的话,或者我对谷歌A Async功能的方式有误解()。

问题回答

你是正确的。 如果浏览器在发送大会跟踪信标(如被点击)之前离开该页,则不会记录该活动。 但是,这并不是像同仁法一样的,因为发送跟踪信标的过程是同步的;旧的法典在这方面也发挥了同样的作用。 如果跟踪确实如此重要,你可以做这样的事情:

function track(link) {
  if (!_gat) return true;
  _gaq.push([ _trackEvent ,  stuff ]);
  setTimeout(function() {location.href=link.href }, 200);
  return false;
}

...

<a href="example.com" onclick="return track(this);"></a>

如果大会已经装满(很可能不会使用户等待这么长时间),那么这就会阻止浏览器上下页。 然后,它发送了该事件,并等待200毫米秒将用户送到被点击的链条。 这增加了记录这一事件的可能性。 你们可以通过延长时间来增加这种可能性,但这也可能伤害到用户在这一进程中的体验。 这给你留下了一种平衡。

我也谈到这一问题,决心找到一个real解决办法。

如何将这一职能推向问题?

  // Log a pageview to GA for a conversion
  _gaq.push([ _trackPageview , url]);
  // Push the redirect to make sure it happens AFTER we track the pageview
  _gaq.push(function() { document.location = url; });

http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920”rel=“nofollow” 谷歌文献,用于全球分析(自这个问题的多数其他答案以来,新版本)。 现在,你可以很容易地指出退步。

var trackOutboundLink = function(url) {
   ga( send ,  event ,  outbound ,  click , url, { hitCallback :
     function () {
     document.location = url;
     }
   });
}

为了明确起见,我建议使用这一辛迪加,这使人们更清楚地看到你重新派遣哪些财产,并更容易增加:

            ga( send ,  event , {
                 eventCategory :  Homepage ,
                 eventAction :  Video Play ,
                 eventLabel : label,
                 eventValue : null,

                 hitCallback : function()
                {
                    // redirect here
                },

                 transport :  beacon ,

                 nonInteraction : (interactive || true ? 0 : 1)
            });

[Hre s a

此外,我还添加了<条码>运输<>/条码>的参数:<条码>。 (由于它酌情自动设定而实际上不需要):

This specifies the transport mechanism with which hits will be sent. The options are beacon , xhr , or image . By default, analytics.js will try to figure out the best method based on the hit size and browser capabilities. If you specify beacon and the user s browser does not support the navigator.sendBeacon method, it will fall back to image or xhr depending on hit size.

因此,在使用navigator.beacon 航行打断了跟踪。 遗憾的是,Microsoft对海滩的支持 ,因此,你仍应将该回头放在背上。

如果是手脚的话,你就应当打上警钟:

_gaq.push([ _set ,  hitCallback , function(){
  document.location = ...
}]);

发送数据

_gaq.push([ _trackEvent 

事件处理

e.preventDefault();
e.stopPropagation();

我试图制定新的做法,在我们为自己建造卢爱拉,并且要求这样做的时候,我们只是在收到答复(即我们寄给用户)时:

使用:

  trackPageview(url, function() { document.location = url; });

守则(CrumbleCookie from:)

/** 
 * Use this to log a pageview to google and make sure it gets through
 * See: http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=5f11a529100f1d47&hl=en 
 */
function trackPageview(url, fn) {
  var utmaCookie = crumbleCookie( __utma );
  var utmzCookie = crumbleCookie( __utmz );

  var cookies =  __utma=  + utmaCookie +  ;__utmz=  + utmzCookie;

  var requestId =    + (Math.floor((9999999999-999999999)*Math.random()) + 1000000000);
  var hId =    + (Math.floor((9999999999-999999999)*Math.random()) + 1000000000);

  var utmUrl =  http://www.google-analytics.com/__utm.gif ;
  utmUrl +=  ?utmwv=4.8.9 ;
  utmUrl +=  &utmn=  + requestId;
  utmUrl +=  &utmhn=  + encodeURIComponent(window.location.hostname);
  utmUrl +=  &utmhid=  + hId;
  utmUrl +=  &utmr=- ;
  utmUrl +=  &utmp=  + encodeURIComponent(url);
  utmUrl +=  &utmac=  + encodeURIComponent(_gaProfileId); 
  utmUrl +=  &utmcc=  + encodeURIComponent(cookies);

  var image = new Image();
  image.onload = function() { fn(); };
  image.src = utmUrl;
}

/**
 *  @author:    Danny Ng (http://www.dannytalk.com/read-google-analytics-cookie-script/)
 *  @modified:  19/08/10
 *  @notes:     Free to use and distribute without altering this comment. Would appreciate a link back :)
 */

// Strip leading and trailing white-space
String.prototype.trim = function() { return this.replace(/^s*|s*$/g,   ); }

// Check if string is empty
String.prototype.empty = function() {
    if (this.length == 0)
        return true;
    else if (this.length > 0)
        return /^s*$/.test(this);
}

// Breaks cookie into an object of keypair cookie values
function crumbleCookie(c)
{
    var cookie_array = document.cookie.split( ; );
    var keyvaluepair = {};
    for (var cookie = 0; cookie < cookie_array.length; cookie++)
        {
        var key = cookie_array[cookie].substring(0, cookie_array[cookie].indexOf( = )).trim();
        var value = cookie_array[cookie].substring(cookie_array[cookie].indexOf( = )+1, cookie_array[cookie].length).trim();
        keyvaluepair[key] = value;
    }

    if (c)
        return keyvaluepair[c] ? keyvaluepair[c] : null;

    return keyvaluepair;
}

利用上下调而不是上下调,也可能有所帮助。 它没有消除种族状况,但它使大会有一个头开始。 也有人对点击链路和拖拉开路,然后拖走 mo子表示关切,但这种情况可能微不足道。





相关问题
Web Analytics for Platform with Custom Events

I m building a platform that produces websites. Think wordpress.com as a similar example. Each site is going to be a subdomain of my domain like abc.mydomain.com or xyz.mydomain.com. I have a few ...

Removal of homepage login users from analytics

The problem I am having is filtering out the users that come to our homepage just to login, since we have the client button on the homepage (and yes I ve tried to get them to put it somewhere else). ...

Finding runs of a particular value

I have a table in Oracle 10 that is defined like this: LOCATION HOUR STATUS -------------------------------------- 10 12/10/09 5:00PM 1 10 12/10/09 6:00PM 1 ...

tracking download completions from a website/cdn

I have a Drupal website where users are clicking on a link that initiates a file download from a content delivery network (CDN). A script is tracking the number of users who click the link to begin ...

Update based on subquery fails

I am trying to do the following update in Oracle 10gR2: update (select voyage_port_id, voyage_id, arrival_date, port_seq, row_number() over (partition by voyage_id order by arrival_date) as ...

Google Analytics _trackEvent troubles

I m having some noob troubles with Google Analytics and _trackEvent. Using it seems straight forward in the documentation, but I can t get this simple example to work. The call to _trackEvent fails ...

热门标签