Google Analytics和三星智能电视应用

时间:2022-10-17 15:50:59

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

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

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

它是一个基于Javascript的应用程序,我已经尝试了SamsungDForum上提供的所有解决方案,但没有人工作。

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

在主index.html文件的部分中,我加载了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>

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.

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

What I am doing wrong?

我做错了什么?

3 个解决方案

#1


7  

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才能将带有GA代码段的文件放入其中。该文件必须位于远程服务器上,因为Samsung Smart TV应用程序适用于localhost,GA忽略来自本地的调用。

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

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

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

  _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, "_")]);
  };

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

所以在应用程序的某个地方调用示例trackPage(“/ sports / football / barcelona chelsea”)将生成具有精确网址的GA跟踪页面:

 /samsung/sports/football/barcelona_chelsea

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.

它非常高效 - 你可以玩GA Real时间,你可以看到它有多好用。由于GA工作异步,iframe永远不会重新加载。

#2


1  

As far as i know you need to link to it using an Iframe, otherwise it will not fire the events.

据我所知,您需要使用Iframe链接到它,否则它不会触发事件。

<iframe src='http://yourwebserver.com/ga-code-application-start.html' width='0' height='0'/></iframe>

#3


1  

I would recommend - and ended up with- implementing your/my own, with for example an Ajax call with GET to Google Analytics like described here https://*.com/a/24181771/174953 Especially since all needed parameters can be found in GA's own documentation https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#content

我建议 - 并最终实现您/我自己的,例如使用GET向Google Analytics调用Ajax,如此处所述https://*.com/a/24181771/174953特别是因为可以找到所有需要的参数在GA自己的文档中https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#content

I discovered in Samsungs forums that the iframe option didn't work on all models, I believe not on 2013+

我在三星论坛上发现iframe选项并不适用于所有型号,我相信不会在2013年以上

#1


7  

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才能将带有GA代码段的文件放入其中。该文件必须位于远程服务器上,因为Samsung Smart TV应用程序适用于localhost,GA忽略来自本地的调用。

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

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

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

  _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, "_")]);
  };

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

所以在应用程序的某个地方调用示例trackPage(“/ sports / football / barcelona chelsea”)将生成具有精确网址的GA跟踪页面:

 /samsung/sports/football/barcelona_chelsea

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.

它非常高效 - 你可以玩GA Real时间,你可以看到它有多好用。由于GA工作异步,iframe永远不会重新加载。

#2


1  

As far as i know you need to link to it using an Iframe, otherwise it will not fire the events.

据我所知,您需要使用Iframe链接到它,否则它不会触发事件。

<iframe src='http://yourwebserver.com/ga-code-application-start.html' width='0' height='0'/></iframe>

#3


1  

I would recommend - and ended up with- implementing your/my own, with for example an Ajax call with GET to Google Analytics like described here https://*.com/a/24181771/174953 Especially since all needed parameters can be found in GA's own documentation https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#content

我建议 - 并最终实现您/我自己的,例如使用GET向Google Analytics调用Ajax,如此处所述https://*.com/a/24181771/174953特别是因为可以找到所有需要的参数在GA自己的文档中https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#content

I discovered in Samsungs forums that the iframe option didn't work on all models, I believe not on 2013+

我在三星论坛上发现iframe选项并不适用于所有型号,我相信不会在2013年以上