Add code google analytics

I want include google analytics in my app.
Here code:

var return_doc  = `<?xml version="1.0" encoding="UTF-8" ?>
         
<document>
                            <head>
                              <script type="text/javascript">
                              var _gaq = _gaq || [];
                              _gaq.push(['_setAccount', 'UA-XXXXXXXX']);
                              _gaq.push(['_trackPageview']);
                              (function() {
                              var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                              ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                              var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                              })();
                              function timerTracking()
                              {
                                  _gaq.push(['_trackPageview'])
                                  t=setTimeout("timerTracking()",900000);
                              }
                              timerTracking();
                            </script>
                            <style>
                         
                            </style>
                            </head>
                            <stackTemplate

But it not working.

Can you guide to use this?


Thanks,

Answered by Technology Evangelist in 111184022

Hi thanhloc93,


I expect that the Google Analytics library is designed for use only with web pages based on HTML, which is different than TVML, which is informing native layouts based on the provided XML markup.


You will have to reach out to Google to see if they have an offering that is compatible with views rendered using TVML. You may need to leverage their native libraries instead, but a web-based library is very unlikely to work.

Accepted Answer

Hi thanhloc93,


I expect that the Google Analytics library is designed for use only with web pages based on HTML, which is different than TVML, which is informing native layouts based on the provided XML markup.


You will have to reach out to Google to see if they have an offering that is compatible with views rendered using TVML. You may need to leverage their native libraries instead, but a web-based library is very unlikely to work.

With some dummy objects and a few tweaks it's actually possible to use analytics.js. Here is an example how we did it: https://github.com/shopgate/tvjs-analytics

Add code google analytics
 
 
Q