Hi Armin,
Does Laytheme support Google Analytics or Clicky?
Where would I add the provided tracking script?
If tracking code can be added, does it track each page and URL? I know that this theme is a "single page" ,but I'm unsure of how that relates to tracking.
Thank you for your help!
-
Google Analytics or Clicky tracking
-
Hey! You can put your tracking code inside "Lay Options" -> "Custom CSS & HTML" -> "Custom <head> Content"
Yeah because its a single page application, google analytics doesn't track each page and url out of the box.
https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications#overviewHowever, you can easily make this work by using autotracker
https://github.com/googleanalytics/autotrackIn your "Custom <head> Content" field you can put:
<script> window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; ga('create', 'UA-XXXXX-Y', 'auto'); ga('require', 'autotrack'); ga('send', 'pageview'); </script> <script async src='https://www.google-analytics.com/analytics.js'></script> <script async src=' https://cdnjs.cloudflare.com/ajax/libs/autotrack/0.6.5/autotrack.js'></script>
Of course you need to replace UA-XXXXX-Y with your UA id
I'm not sure about Clicky, I haven't used it yet.
-
Thank you Armin!
I will try to add the script for Google Analytics.I tried Clicky with Lay Theme and it works like a charm. The team at Clicky mentioned something about Lay uses History API so everything works well. Thanks again for your great theme and support.
Matt -
Ah thats great to hear!!
-
Hey everybody,
So regarding google analytics and lay theme.
This should work:
In your "Custom <head> Content" field you can put:
<!-- Google Analytics --> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview'); </script> <!-- End Google Analytics -->
Replace XXXXX with your tracking number.
from: https://developers.google.com/analytics/devguides/collection/analyticsjsand this for tracking pageviews:
<script> window.laytheme.on('newpageshown', function(){ ga('send', 'pageview', location.pathname); }); </script>
no extra library like "autotrack" needed
docs: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
-
Hi @arminunruh
This still doesn't seem to be working.Do we still need to load the autotracker.js ?
https://github.com/googleanalytics/autotrack -
Hey!
Oh I thought it would work and didn't test it properly.
So I tested this and this works.
Replace UA-XXXXXX-X with your tracking ID:<script> window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; ga('create', 'UA-XXXXXX-X', 'auto'); // Replace the following lines with the plugins you want to use. ga('require', 'eventTracker'); ga('require', 'outboundLinkTracker'); ga('require', 'urlChangeTracker'); // ... ga('send', 'pageview'); </script> <script async src="https://www.google-analytics.com/analytics.js"></script> <script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/2.4.1/autotrack.js"></script> <script> window.laytheme.on('newpageshown', function(){ ga('set', 'page', location.pathname); ga('send', 'pageview'); }); </script>
Then in your google analytics dashboard go to
"Behaviour" → "Website Content" → "All Pages"
And then make sure to select the date range that covers the current day:
then you'll see the pages that were visited today:
-
This post is deleted!