On which pages should I put the code of google Analytics?

Asked

Viewed 741 times

1

The manual says to put on all pages, but this includes the pages that can only be accessed after login?

There’s a way google Analytics can see these pages?

For example, if my only page with Analytics is the index.php, this will make it not correctly computed the time the user has spent on the site, the bounce index etc?

3 answers

5


The answer to the 3 questions is yes.

We need to put the tracking code on every page you want to track. Even if the page has authentication, the Analytics can "see" the relevant data, and provide the features we want, such as number of accesses, length of stay, rejection rate etc... and the most important thing, which is the behavioral flow.

The location indicated by google for the placement of the tracking code is between the tags head, 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 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 that of google itself, to make the load asynchronous.

2

Exact! You must implement within the site.

A good practice is to use a Tag Manager like Google Tag Manager, as it makes loading asynchronous. This is just one of the advantages of using a tag manager.

  • 1

    I gave +1 in this answer, for the important tip of the tag maganer, but I did not find that she answered satisfactorily the question, so since it’s been a while since I posted, and already know the answer, I decided to do a tbm with more information.

-1

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.