Analytics
2K members online now
2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

installing the tracking code on each web page

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi everyone, 

 

This seems like a really silly question, but I have to ask it because I have been unable to find a simple answer with a google search. How do I install the Google Analytics tracking code on each page of my website,  and ensure that I can tell which page is which when I am looking at the data from the Analytics viewpoint?  I am looking for step by step instructions, ideally for a Wordpress site. 

 

Thank you!

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by James_Clemens (Top Contributor)
July

installing the tracking code on each web page

Top Contributor
# 2
Top Contributor

Hi @Emily S :-)

Is your site on wordpress.com or do you have your own hosting with WordPress installed on it?

wordpress.com does not support google analytics unless you have one of their paid business plans.

https://en.support.wordpress.com/google-analytics/

 

If you have self hosted WordPress, how you install analytics will depend on the theme you are using.
Most themes (but not all) will have an theme admin option to add script to the head or footer of the site.
If your theme supports this, then this would be the easiest way to add the tracking code.

If your theme does not support it, then the next most acceptable way to add the tracking is via one of the free 3rd party plugins available from wordpress.org

I've often used the following one without any issues:
https://wordpress.org/plugins/google-analytics-dashboard-for-wp/

 

They have detailed information and videos etc on how to install and authorize it the plugin.

https://deconf.com/google-analytics-dashboard-wordpress/

 

For WordPress the tracking does not get manually added to each site page.. it gets installed once via either plugin or an option provided within your theme settings.. and will then be applied to all pages site-wide.

Best way to get acquainted with google analytics and its reporting features is via

the free learning resource Analytics Academy

- Google Analytics for Beginners

https://analytics.google.com/analytics/academy/course/6

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

View solution in original post

Marked as Best Answer.
Solution
Accepted by James_Clemens (Top Contributor)
July

installing the tracking code on each web page

Top Contributor
# 2
Top Contributor

Hi @Emily S :-)

Is your site on wordpress.com or do you have your own hosting with WordPress installed on it?

wordpress.com does not support google analytics unless you have one of their paid business plans.

https://en.support.wordpress.com/google-analytics/

 

If you have self hosted WordPress, how you install analytics will depend on the theme you are using.
Most themes (but not all) will have an theme admin option to add script to the head or footer of the site.
If your theme supports this, then this would be the easiest way to add the tracking code.

If your theme does not support it, then the next most acceptable way to add the tracking is via one of the free 3rd party plugins available from wordpress.org

I've often used the following one without any issues:
https://wordpress.org/plugins/google-analytics-dashboard-for-wp/

 

They have detailed information and videos etc on how to install and authorize it the plugin.

https://deconf.com/google-analytics-dashboard-wordpress/

 

For WordPress the tracking does not get manually added to each site page.. it gets installed once via either plugin or an option provided within your theme settings.. and will then be applied to all pages site-wide.

Best way to get acquainted with google analytics and its reporting features is via

the free learning resource Analytics Academy

- Google Analytics for Beginners

https://analytics.google.com/analytics/academy/course/6

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

installing the tracking code on each web page

Follower ✭ ✭ ✭
# 3
Follower ✭ ✭ ✭

Hi @Emily S,

 

as an addendum to @Bronwyn V's answer: do you use a commercial theme like Ronneby, Divi or X or a rular one like twentysixteen?

This is important for answering your question right, because most of the commercial themes offer/need an individual solution/integration.

 

Aloha

 

Arne

installing the tracking code on each web page

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hi Arne and Bronwyn, 

Thanks so much for the replies. I have a code installed on Wordpress that is applied throughout the entire site and have been tracking visitors via Google Analytics. However, I want to install the code on each web page of the site separately, instead of one code fo the entire site, so that I can understand user behaviour once they come to the web page. 

 

I am using WordPress 4.8 running Twenty Sixteen Child theme. I would like to ideally put a code on each page so that I can track where people go (Home, Petition, Facts, FAQ) and then also when they have signed a petition. I realize an action is a different bit of tracking, but I am going to see if I can start with page by page and then build on my skills from there! 

 

Here is the website in case that helps you give advice: keeptransitpublic.ca

Re: installing the tracking code on each web page

[ Edited ]
Top Contributor
# 5
Top Contributor

Hi :-)

I am using WordPress 4.8 running Twenty Sixteen Child theme. I would like to ideally put a code on each page so that I can track where people go (Home, Petition, Facts, FAQ) and then also when they have signed a petition. I realize an action is a different bit of tracking, but I am going to see if I can start with page by page and then build on my skills from there! 

 

1) WordPress expects and requires that javascript be loaded in a particular manner.

2) Imho, learning Google Analytics, should be done with code that is installed correctly and according to best practices for the particular platform the site is installed on. This helps in reducing code implementation/configuration errors, which helps you to trust in the accuracy of the data and what it represents in relation to data numbers and visitor site behaviour.

 

3) With code not correctly installed on all pages, you are going to end up with gaps in the reporting

What you are wanting to track can be done with a 'normal' installation of Google Analytics via the theme or a plugin.

 

Using GA's Behaviour Flow and Goals/Goal Flow

http://marketlytics.com/blog/behavior-flow-reports-google-analytics

http://www.lunametrics.com/blog/2012/08/06/goal-flow-how-visitors-really-move-through-funnel/

 

To add the code to individual pages, your theme will either need to support adding script to individual pages, 

or you will need to find a plugin that enables you to do this, or you will need to create a child theme for making the changes.

Directly editing your current active theme to make coding changes is not recommended and does not follow WordPress best practices.
1) The code changes will be overwritten each time the theme is updated

2) It makes breaking your site a lot easier.

 

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

installing the tracking code on each web page

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi Bronywn, 

Thanks so much for your reply. 

I am pretty new to all of this so I am going to paraphrase to make sure I understand. Are you saying that it is not advisable to try to add code to track each page using the current Wordpress set up that I have? If so, that is just fine by me. 

 

Now I have moved on to try to set up event tracking, but I am finding this totally confusing and unsure even where to begin. If you have a great link with info for beginners, please share.

installing the tracking code on each web page

Top Contributor
# 7
Top Contributor

Hi @Emily S :-)

 

Thanks so much for the replies. I have a code installed on Wordpress that is applied throughout the entire site and have been tracking visitors via Google Analytics.

This is fine and how it should be done

 

However, I want to install the code on each web page of the site separately, instead of one code fo the entire site, so that I can understand user behaviour once they come to the web page. 

This is not fine and not recommended

 

Now I have moved on to try to set up event tracking, but I am finding this totally confusing and unsure even where to begin. If you have a great link with info for beginners, please share.

What is it you are trying to track using events?


The plugin i linked to earlier for installing GA on your site, has options in it for event tracking a variety of scenarios

Downloads
Emails
Outbound links
Affiliate links
Fragment identifiers
Telephone
Page Scrolling Depth
Custom event categories, actions and labels using annotated HTML elements

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

installing the tracking code on each web page

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Hi Bronywn, 

Thanks for all your replies. I appreciate all of your attention and help.

 

I am trying to track signatures on an online petition http://www.keeptransitpublic.ca/#petition

 

The way I see it, I can do this two ways:

(1) when the user clicks the "Sign Now" button and 

(2) when the site automatically sends out an email (when a person signs, an automatic email is sent out).

 

I didn't create the site so I don't know the PHP code for anything. Or even how to code, really. I am setting up the Google Analytics to track how people get to the site and if they are signing the petition. So this is the #1 goal for me.

 

I will track either, whichever is more straightforward for a n00b.

 

Thank you!

 

Emily 

Re: installing the tracking code on each web page

[ Edited ]
Top Contributor
# 9
Top Contributor

Hi @Emily S :-)

is the site just a single page with anchor links or are there seperate site pages?

 

Do you have a plugin installed that will enable you to add script to the footer of the site?

if so, then the following should work
It will track an event when the petition form is submitted.. 
atm the event category and action are set to transit petition and submit respectively.

<script type='text/javascript'>
var form = document.getElementsByClassName('dk-speakout-petition');

// Adds a listener for the "submit" event.
form.addEventListener('submit', function(event) {

  // Prevents the browser from submitting the form
  // and thus unloading the current page.
  event.preventDefault();

  // Creates a timeout to call `submitForm` after two seconds.
  setTimeout(submitForm, 2000);

  // Keeps track of whether or not the form has been submitted.
  // This prevents the form from being submitted twice in cases
  // where `hitCallback` fires normally.
  var formSubmitted = false;

  function submitForm() {
    if (!formSubmitted) {
      formSubmitted = true;
      form.submit();
    }
  }

  // Sends the event to Google Analytics and
  // resubmits the form once the hit is done.
  ga('send', 'event', 'transit petition', 'submit', {
    hitCallback: submitForm
  });
});
</script>

https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#handling_timeo...

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

installing the tracking code on each web page

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

Hi Bronwyn, 

Thank you so much! I had applied the Insert Headers & Footers Plugin, so I added your code above to the Footers plugin underneath my Google Retargeting plugin. Where will I be able to access the results of the information it is gathering? Should I install the Plugin you linked to earlier: https://wordpress.org/plugins/google-analytics-dashboard-for-wp/

 

Thanks again!