I'm trying to integrate Google Analytics in my Smart TV Application.
It is a Javascript based application, and I have tried all the solutions available on the SamsungDForum, but no one works.
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>
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.
What I am doing wrong?
The use of Google Analytics is somewhat problematic on Samsung Smart TVs which run applications locally (so does LG, in the case of which this setting is optional). There are three possible solutions of this problem:
Starting 15 June 2021, Google Play Movies & TV app will no longer be available on Samsung Smart TVs. The YouTube app will continue to be available for your movies and shows needs 1.
But there's more — because Samsung smart TVs also have games, music apps, smart home apps and others. If you've just bought yourself a new set such as the excellent Samsung QN90B, the first thing you'll want to do is load it up with some of these apps. Not sure where to find the best Samsung smart TV apps? Read on and we'll tell you where to start.
Use Google Assistant on your Samsung TV Google Assistant has taken up residence in a new place: your Samsung smart TV! Yes, you read that correctly. You can now talk to Google to quickly access entertainment, get answers on screen, control smart devices, and more using your voice.
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"/>
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, "_")]);
};
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
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.
As far as i know you need to link to it using an Iframe, otherwise it will not fire the events.
<iframe src='http://yourwebserver.com/ga-code-application-start.html' width='0' height='0'/></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With