How to add code google analytics with tvml, tvjs

276 Views Asked by At

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?

1

There are 1 best solutions below

0
On

TVML doesn't have support for the script tag to inline JS in your templates.

Instead, you should include the JS script inside your main JS file (where you have App.onLaunch).

Note that, TVML/TVJS doesn't have 'pages', so page views won't track like they would on web. Also, the Javascript environment is different to a browser, with some API's not available, so the Google Analytics library might not work with TVJS out of the box.