Google Analytics and Samsung Smart TV Apps

前端 未结 3 1598
無奈伤痛
無奈伤痛 2021-01-02 23:51

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 Samsu

相关标签:
3条回答
  • 2021-01-03 00:07

    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>
    
    0 讨论(0)
  • 2021-01-03 00:10

    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.

    0 讨论(0)
  • 2021-01-03 00:10

    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://stackoverflow.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

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

    0 讨论(0)
提交回复
热议问题