Javascript 我的DOM中的Google Analytics像素在哪里?

Javascript 我的DOM中的Google Analytics像素在哪里?,javascript,google-analytics,Javascript,Google Analytics,我如何使用JavaScript识别已发送的Google Analytics像素(或任何像素)并包含我正在查找的URL参数 我想,既然它是一个跟踪像素,我可以在DOM中查找它,但它看起来好像从未被插入过 有人能想出一种方法来分析谷歌使用javascript(而不是chrome扩展)发出的网络请求吗 差不多 document.whenGooglePixelIsSentDoReallyCoolStuff(function(requestUrl){ }); 有几件事: 1) 跟踪信标并不总是像素。有

我如何使用JavaScript识别已发送的Google Analytics像素(或任何像素)并包含我正在查找的URL参数

我想,既然它是一个跟踪像素,我可以在DOM中查找它,但它看起来好像从未被插入过

有人能想出一种方法来分析谷歌使用javascript(而不是chrome扩展)发出的网络请求吗

差不多

document.whenGooglePixelIsSentDoReallyCoolStuff(function(requestUrl){

});
有几件事:

1) 跟踪信标并不总是像素。有时它们是XHR,有时它们根据情况和/或跟踪器使用,所以如果你只是在寻找像素,你可能找错了地方

2) 您不需要向DOM中添加图像,就可以让它发送请求。只需执行document.createElement('img').src=“path/to/image.gif”就足够了

3) 您不需要使用Chrome扩展来调试Google Analytics,只需加载而不是常规版本

4) 如果您确实不想使用Google Analytics的调试版本,并且希望以编程方式跟踪发送的内容,那么您可以在发送之前覆盖和截获点击

更新(7/21/2015) 你已经改变了你的问题的措辞,因此我将回答新的措辞,说你应该遵循我在上文第4条中给出的建议。下面是一些代码,这些代码可以在OGLEPIxelissentDoreallycooltuff函数运行时与假设的
一起使用:

document.whenGooglePixelIsSentDoReallyCoolStuff = function(callback) {

  // Pass the `qa` queue method a function to get acess to the default
  // tracker object created via `ga('create', 'UA-XXXX-Y', ...)`. 
  ga(function(tracker) {

    // Grab a reference to the default `sendHitTask` function.
    var originalSendHitTask = tracker.get('sendHitTask');

    // Override the `sendHitTask` to call the passed callback.
    tracker.set('sendHitTask', function(model) {

      // When the `sendHitTask` runs, get the hit payload,
      // which is formatted as a URL query string.
      var requestUrl = model.get('hitPayload')

      // Invoke the callback passed to `whenGooglePixelIsSentDoReallyCoolStuff`
      // If the callback returns `false`, don't send the hit. This allows you
      // to programmatically do something else based on the contents of the
      // request URL.
      if (callback(requestUrl)) {
        originalSendHitTask(model);
      }
    });
  });
};
请注意,您必须在创建跟踪器之后,但在发送第一次点击之前运行此功能。换句话说,您必须在以下两行代码之间运行它:

ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');

Google Analytics不使用跟踪像素,至少默认情况下不使用。@Quentin,Analytics调用的端点返回1px gif,因此可以说Google Analytics使用跟踪像素。我更新了我的答案以反映编辑的问题。+1,或者可以使用网络代理,如fiddler(或浏览器中的“网络”选项卡)监控对google-analytics.com的调用(尽管这不是javascript)。