admin管理员组文章数量:1290975
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='.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?
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./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?
Share Improve this question asked Apr 23, 2012 at 12:34 Francesco FacconiFrancesco Facconi 2493 silver badges17 bronze badges3 Answers
Reset to default 7So 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./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./ga-code-application-start.html' width='0' height='0'/></iframe>
I would remend - and ended up with- implementing your/my own, with for example an Ajax call with GET to Google Analytics like described here https://stackoverflow./a/24181771/174953 Especially since all needed parameters can be found in GA's own documentation https://developers.google./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+
本文标签: javascriptGoogle Analytics and Samsung Smart TV AppsStack Overflow
版权声明:本文标题:javascript - Google Analytics and Samsung Smart TV Apps - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741509933a2382548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论