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

查看:133
本文介绍了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>

不幸的是,我无法看到我的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代码片段中,如果您不希望GA计算trackPage, iframe load。

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 )应用程序中的某个地方会产生具有确切网址的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天全站免登陆