On what pages should I put google analytics code?

1

In the manual speak to put on all pages, but does this include pages that can only be accessed after login?

Do you have google analytics to see these pages?

For example, if my only page with analytics is index.php , will not this compute the time the user spent on the site correctly, the bounce rate etc?

    
asked by anonymous 19.04.2016 / 18:36

3 answers

4

The answer to all 3 questions is yes .

You need to place the tracking code on every page you want to crawl . Even the page having authentication, analytics can "see" the relevant data, and provide the features we want, such as number of accesses, dwell time, rejection rate etc ... and the most important imo, which is behavior flow .

The location indicated by google to place the tracking code is among the head tags, as in the example below:

<head>
<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>
</head>

See the help page on developers .

As indicated by @Ricardo Gaya, in the answer above, it is also possible (and indicated) to use a tag manager, such as Google's own , to make the upload asynchronous.

    
07.11.2016 / 16:18
2

Exactly! You must implement within the site's.

A good practice is to use a Tag Manager such as Google Tag Manager as it makes the upload asynchronous. That's just one of the advantages of using a tag manager.

    
03.11.2016 / 02:19
-1

By convention default, JS codes are within <head> </head> of HTML!

But if you put anywhere on the HTML page the script will work normally

    
20.04.2016 / 01:10