Google Analytics 和三星智能电视应用 [英] Google Analytics and Samsung Smart TV Apps

查看:29
本文介绍了Google Analytics 和三星智能电视应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Google Analytics 集成到我的智能电视应用程序中.

I'm trying to integrate Google Analytics in my Smart TV Application.

这是一个基于 Javascript 的应用程序,我已经尝试了 SamsungDForum 上所有可用的解决方案,但没有一个有效.

It is a Javascript based application, and I have tried all the solutions available on the SamsungDForum, but no one works.

在主 index.html 文件的部分中,我加载了 Google Analytics:

In the part of the main index.html file, I load Google Analytics:

<script type='text/javascript' async='true' src='https://ssl.google-analytics.com/ga.js'></script>

然后,我正在跟踪页面入口:

Then, I am tracking the page entrance:

<script type='text/javascript'>
    var _gaq = _gaq || [];
    _gaq.push([ '_setAccount', 'UA-XXXXXXXX-X' ]);
    _gaq.push([ '_setCustomVar', 1, 'Device Information', 'Samsung Smart TV' ]);
    _gaq.push([ '_trackPageview' ]);
    _gaq.push([ '_trackEvent', "Application", "Start" ]);
</script>

很遗憾,我无法在我的 Google Analytics(分析)帐户中看到跟踪的页面.真实账户ID不是UA-XXXXXXXX-X,我在实际代码中使用了正确的ID.

Unfortunately, I cannot see the page tracked inside my Analytics account. Real account id is not UA-XXXXXXXX-X, I am using the correct ID in actual code.

我做错了什么?

推荐答案

所以你需要一个 iframe 来将包含 GA 片段的文件放入其中.该文件必须位于远程服务器上,因为三星智能电视应用程序在本地主机上运行,​​而 GA 会忽略来自本地的调用.

So you need an iframe to put the file with GA snippet inside. The file must be on remote server, because Samsung Smart TV apps works on localhost and GA ignore calls from local.

  <iframe name='ga' src="http://example.com/ga.html" width="0" height="0"/>

如果您不希望 GA 在 iframe 加载时计算 trackPage,您可以从 GA 代码段中删除该行.

From the GA snippet you can remove the line, if you don't want GA to count trackPage on iframe load.

  _gaq.push(['_trackPageview']);

然后在主脚本中添加这个函数:

Then in the main script you add this function:

  var trackPage = function(url) {
    if (window.ga && window.ga._gaq)
      window.ga._gaq.push(['_trackPageview', '/samsung' + url.replace(/ /g, "_")]);
  };

因此调用例如 trackPage("/sports/football/barcelona chelsea") 应用程序中的某处将生成具有确切 url 的 GA 跟踪页面:

So calling for example trackPage("/sports/football/barcelona chelsea") somewhere in the app will produce GA track page with exact url:

 /samsung/sports/football/barcelona_chelsea

它非常有效 - 您可以使用 GA Real time,并且可以看到它的效果如何.由于 GA 异步工作,iframe 永远不会重新加载.

It is very efficient - you can play with GA Real time and you can see how nice it works. As GA works asynchronous the iframe never gets reloaded.

这篇关于Google Analytics 和三星智能电视应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆