【问题标题】:Tracking clicks within iframes with Google Analytics使用 Google Analytics 跟踪 iframe 内的点击次数
【发布时间】:2013-10-06 08:16:34
【问题描述】:

是否有机会跟踪点击并从 iframe 获得推荐流量?

我有管视频网站,我的视频嵌入在许多其他网站上,但是当视频嵌入到其他网站上时,无法找到跟踪 iframe 内链接点击的解决方案

这是来自我网站的嵌入代码

<iframe src="http://mysite.com/embed.php?id=4589"></iframe>

我尝试在 embed.php 中放入类似的东西

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-111111-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('http:' == document.location.protocol ? 'http://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

然后我更改了指向此的链接

<a href="http://mysite.com/video/55454.html" onclick="_gaq.push(['_link', this.href]);return false;">Continue</a>

但这不是解决方案

【问题讨论】:

    标签: javascript php jquery iframe google-analytics


    【解决方案1】:

    如果点击在你应该使用的 iframe 内:

    window.parent._gaq.push(['_trackEvent', eventCategory, eventAtion, eventLabel]);
    

    【讨论】:

      【解决方案2】:

      您可以在 js 文件中添加您的默认 ga 代码,并将其包含在您的所有页面嵌入和视频页面中,即 embed.php、55454.html 等

      要触发事件分析,请使用以下命令,

      //send to analytics
      //    var _gaq = _gaq || []; //if already loaded e.g. single page app, keep comment out
      //    _gaq.push(['_setAccount', 'UA-YOUR-ACCOUNT']); //comment out if single page app
          _gaq.push(['_trackPageview','/home/landingPage']);
      
      //sendEventToAnalytics
      //    var _gaq = _gaq || []; // if single
      //    _gaq.push(['_setAccount', 'UA-YOUR-ACCOUNT']); // if single
      //    _gaq.push(['_trackPageview']); //if single
          _gaq.push(['_trackEvent', eventCategory, eventAtion, eventLabel]);
      

      签入api, https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

      【讨论】:

      • 但我不确定我是否可以通过这种方式跟踪 iframe 内的点击。我已经尝试过了
      • 如果您与 onclick 处理的链接在包含您的 ga 代码的页面内,那么您可以通过调用我发布的“sendEventToAnalytics”代码来跟踪任何事件。您需要做的就是从 onclick 或任何其他 js 事件处理中调用它。当作为 iframe ga 运行时,仍然可以工作,例如在过去,我意识到我的一个应用程序嵌入为来自 ga 的 3rd 方页面的 iframe。
      • 所以在 embed.php 中我应该只使用 onclick="_gaq.push(['_link', this.href]);" 吗?无法理解我在哪里犯错......
      • 是的,但请检查您包含 ga 代码的方式。按照support.google.com/analytics/answer/1008080 的指示,尝试将它放在embed.php 的头部,检查它是否有效,然后使用控制台发出事件或直接从embed.php 测试您的onclick 部分。如果它有效,则将其作为 iframe 进行测试,它的行为方式应该相同。
      猜你喜欢
      • 2013-09-28
      • 1970-01-01
      • 2015-05-30
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      相关资源
      最近更新 更多