Google Analytics and Samsung Smart TV Applications

I am trying to integrate Google Analytics into a Smart TV app.

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

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

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

Then I track the entry to the page:

 <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> 

Sorry, I don’t see the page being tracked in my Google Analytics account. The real account ID is not UA-XXXXXXXX-X, I am using the correct identifier in the actual code.

What am I doing wrong?

+6
source share
3 answers

So, you need an iframe to put the file with the GA fragment inside. The file must be located on the remote server, because Samsung Smart TV applications run on the local host, and GA ignores calls from the local host.

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

From a GA snippet, you can delete a line if you do not want GA to count trackPage when loading an iframe.

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

Thus, to call trackPage("/sports/football/barcelona chelsea") somewhere in the application, a GA track with the exact URL will be created:

  /samsung/sports/football/barcelona_chelsea 

It is very effective - you can play with GA Real time, and you can see how well it works. Because GA works asynchronously, the iframe never reloads.

+7
source

As far as I know, you need to reference it using an iframe, otherwise it will not fire events.

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

I would recommend - and end up with your / my own, for example, with an Ajax call with GET in Google Analytics, as described here fooobar.com/questions/913926 / ... Moreover, all the necessary parameters can be found in your own documentation GA https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#content

I found in Samsung forums that the iframe option does not work on all models, I suppose not in 2013+

+1
source

Source: https://habr.com/ru/post/913925/


All Articles