Moodle and Google Analytics

Moodle and Google Analytics

by Satish Talim -
Number of replies: 39
Is there any way I can add the Google Analytics code to my site created using Moodle?
Average of ratings: -
In reply to Satish Talim

Re: Moodle and Google Analytics

by Eloy Lafuente (stronk7) -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Hi Satish,

I guess that the theme/xxxx/footer.hml (where xxxx is the theme you're using in the site), is a good candidate. Near the end of the file, before the closing </body> tag, I guess.

Ciao smile
In reply to Eloy Lafuente (stronk7)

Re: Moodle and Google Analytics

by Satish Talim -
Thanks Eloy. Have added the code; shall monitor and check if successful.

Satish
In reply to Satish Talim

Re: Moodle and Google Analytics

by Scott Wilson -

If our Moodle site is hosted by a vendor, do I have access to the footer.html file ... in order to add the Google code?  If so, how do I get to it?  Or do I need to ask the vendor to insert the code?

Scott

In reply to Scott Wilson

Re: Moodle and Google Analytics

by Stefan Ramaker -
Hello Scott,

to download the footer.html you will need a ftp account. If this is not available your vendor can add the code. You should know that this takes about 5 min smile.

I am not sure, but I know, that the code has to get placed before the ending body tag </body>.

So maybe it would be also okay if you add this code on the frontpage in the html-editor in HTML mode. If I am wrong or moodle does not allow these kind of tags, then maybe someone correct my, but it is worth to try it.

Greetings

Stefan
In reply to Stefan Ramaker

Re: Moodle and Google Analytics

by Satish Talim -
I added the Google Analytics (GA) code in my themes' footer.html just before the </body> tag and it works. Have started getting the reports from GA.
In reply to Satish Talim

Re: Moodle and Google Analytics

by Scott Wilson -

Stefan and Satish,

Thank you for your responses. Since our site is being hosted by a Moodle partner, I don't seem to have access to the code for themes or the footer.html file ... so think that I will need to contact them to add the code.

Scott

In reply to Scott Wilson

Re: Moodle and Google Analytics

by A K -
Do Moodle partners usually place that level of restriction on access to a Moodle system?
In reply to Satish Talim

Re: Moodle and Google Analytics

by Damian Lopez -

Hi

 

I know that change in the source code is immediate after to just to put the script in the footer.html, but in my case isn't working. I need to do anything else?, restart the apache web server? any suggestions?

In reply to Damian Lopez

Re: Moodle and Google Analytics

by Joao Freitas -
Hi Damian,

You robably already sorted it out, but for those reading this, the GA code has changed a bit and now they suggest putting it right before the </HEAD> tag on each page.

The easiest solution is, as it it is mentioned above, going to the Site Administration block "Site Administration > Appearance > Additional HTML " and chose where to automatically put it in each and every page  (though I myself am struggling with some erratic behaviout at the time being)...

Hope this helps.

Regards,

-- joão

In reply to Satish Talim

Re: Moodle and Google Analytics

by Klaus Brune -

I just put the Google Analytics code on my own site, but, being a programmer and therefore somewhat of a control freak, I can see where we might want some added functionality.

For instance, I don't want my own visits to the site as I'm building courses to show up in my statistics. Ideally, I'd also like to separate statistics for visitors, teachers, students, etc.

I'm not familiar enough with the Moodle code to do this without a bit of research, though. If anyone reading this happens to know what PHP variable holds the data for the currently logged user, that would be great. If I find it first, I'll post it here.

Essentially, I want to duplicate what Drupal's add-in module for Google Analytics does...

  1. Allow specific user roles to be excluded.
  2. Allow user-defined data to be passed on to G.A. such as the user role of the visitor. It's useful to know when 90% of the hits are from teachers, not students, right? smile
In reply to Klaus Brune

Re: Moodle and Google Analytics

by Josh OCB -
Hi Klaus,

Did you manage to get google analytics working with the advanced functionality? I'd be interested to hear if you found a solution.

Thanks
In reply to Klaus Brune

Re: Moodle and Google Analytics - distinguish roles

by Joyce Seitzinger -
Hi Klaus,
Have you made any progress with the ability to distinguish between staff, visitors & student visits? Would be so useful to have.

Thanks,
Joyce
In reply to Joyce Seitzinger

Re: Moodle and Google Analytics - distinguish roles

by Martin Ryan -

I'm another wondering about the possibility of that kind of information being collectable.

Regards

Martin

In reply to Klaus Brune

Re: Moodle and Google Analytics

by J Rogers -
One thing you can do from the Google Analytics side is to filter out the IP addresses of particular computers. I use the same computer every day for Moodle testing and development and use this approach.
In reply to J Rogers

Re: Moodle and Google Analytics

by William Oakes -
Hi J ( or anyone else who can help)

I put the Google Analytics script in the footer.html of the Custom Corners theme. It does not show anything on the website footer and does not increment the counter on the google site.

You would think something this easy to do would be easy to do. But not for me!

Thanks,

Bill

In reply to Satish Talim

Re: Moodle and Google Analytics

by Jonathan Konrad -
Can I register just my course page with Google Analytics? I tried copying and pasting the url with all the "view.php?id=498" stuff in it and Google will not register the site.

I do not wish to analyze our whole Moodle. Just my course. I can make a custom theme for just my course and paste Google's code in the footer. However, I'm not sure how to register it with Google in the first place.

Any thoughts would be helpful. Thank you.
In reply to Satish Talim

Re: Moodle and Google Analytics

by Jon Fila -
I'm still trying to find a way to install the Google Analytics script on my site. Is there anyone here who is currently using this?
In reply to Jon Fila

Re: Moodle and Google Analytics

by Jeffery Watkins -
Jon,

Send me an email and I will do it for you.

Jeff
In reply to Jeffery Watkins

Re: Moodle and Google Analytics

by Kyle Johnson -
Has anyone successfully got this to work?

The block add in doesn't work as stated and it seems to be abandoned.
In reply to Kyle Johnson

Re: Moodle and Google Analytics

by Jon Fila -

Sorry Jeff, I didn't come back to this thread after my last post. I've left the organization I was with that hosts with your company.

I did figure out how to do this though by pasting the Google Analytics code into the footer of each theme.

In reply to Satish Talim

Re: Moodle and Google Analytics

by Graham Clark -

My Moodle 2.0 installation uses a theme called "Anomaly" which doesn't appear to include a footer.html file. In which case, where do I paste the snippet of Google code? Thanks.

In reply to Graham Clark

Google Analytic w/ Moodle theme (NO footer.html)

by e m -

Hello.  I'm new.  Started working w/ Moodle about a week ago.  I too am wondering if there is a method of adding Google analytics into a theme that does not seem to have a footer.html file.

I'm using a newer Moodle theme (2.0 I would suspect) and I believe it's called Binarius?

Any help would be greatly appreciated/thank you in advance.

Eric

In reply to Graham Clark

Re: Moodle and Google Analytics

by Judy Unrein -

Same thing here... I have access to my files and I have my analytics code to paste in, but I don't see any html files in the whole installation.

In reply to Graham Clark

Re: Moodle and Google Analytics

by Murad Parambadan -

In 2.0 go to Site Administration > Appearance > Additional HTML and copy the Tracking Code from Google Analytics into the 'Within Header' box.

Average of ratings: Useful (3)
In reply to Murad Parambadan

Re: Moodle and Google Analytics

by Andrew Simpson -

Hi Murad

This feature would be fantastic - but I can't find it under Site Administration?  I am running Moodle 2.0 - does this feature have to be activated?

I am simply trying to add the Google Analytics code to this site.

Thanks

Andrew

In reply to Murad Parambadan

Re: Moodle and Google Analytics

by Marius Butuc -

For page load performance I'd recommend including the Tracking Code from Google Analytics somewhere in the footer instead of header.

In reply to Satish Talim

Re: Moodle and Google Analytics

by Sherwin Binarao -

Hello everyone.

Google Analytics is a very good statical tool for our Moodle sites.

But instead of changing the codes in the footer you might want to add the GA codes to Site Administration > Appearance > Additional HTML

These settings allow you to specify HTML that you want added to every page. You can set HTML that will be added within the HEAD tag for the page, immediately after the BODY tag has been opened, or immediately before the body tag is closed. Doing this allows you add custom headers or footers on every page, or add support for services like Google Analytics very easily and independent of your chosen theme.


Thanks,

Sherwin

Average of ratings: Useful (4)
In reply to Sherwin Binarao

Re: Moodle and Google Analytics

by David Kimball -

Thanks Sherwin for replying on this two year old plus thread.  Exactly what I came looking for.  Started tracking immediately.

And for those that follow, if you are following more than one website in GA, you will need to put that extra code in the header.

In reply to David Kimball

Re: Moodle and Google Analytics

by kiwami livingston -

Ditto

In reply to kiwami livingston

Re: Moodle and Google Analytics

by Mark Glynn -

I'm very interested in what reports/dashboards that you are generating using Google Analytics. GA is great and can produce data on nearly everything for you but the challenge for me is identifying the right reports to generate.

 

Any thoughts/advice would be welcome

 

Kind regards,

 

Mark

In reply to Mark Glynn

Re: Moodle and Google Analytics

by Patricia Loofbourrow -

What you track really depends on why you have the site there. My moodle is a paid educational subdomain of a informational for-profit site (in other words, a business venture).

So my tracking is aimed at where people are coming from (referring link), the bounce rate (how many left without clicking anything), and how many showed up (unique visitors).

My purpose with this is to figure out ways to increase my visits from a particular website, get them to click on the front page (either to my main site or to look around), or (ultimately) to buy a course! big grin

You main purpose might be very different. A local course that only children from a particular school can enroll in might not need GA at all.

In reply to Patricia Loofbourrow

Re: Moodle and Google Analytics

by David Boch -

HI Patricia,


have you used Facebook pixel? Is the procudure of implementation the same as for GA? I am stuck with this Facebook pixel in and I can't figure out how to make it work. I want to add main Facebook pixel and event pixels on particular pages. Any ideas?

Thanks.

David

In reply to Sherwin Binarao

Re: Moodle and Google Analytics

by Joao Freitas -

Hello All,

I tried to insert the GA code using this procedure and it is nor working (Moodle 2.8.5)

  • I am quite sure the code is exactly as it shows on the Google Analytics Admin page
  • I used the Site Administration > Appearance > Additional HTML approach
  • I inserted it using the option that puts it right before the </HEAD>
  • I already checked and the code is indeed on the page,
    however
  • When checking on GA Admin page it says it is not installed and hence it does not do any stats
The only thing that is not 100% is that the page code shows an odd <meta name=...> (you would expect it to be at the top of the page near the other meta tags) that shows immediately after the "</script>" at the bottom of the code snippet. Here's what the page source shows:
...
<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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-99999999-1', 'auto');
ga('send', 'pageview');

</script> <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body ...
Could this meta tag be the culprit? They do say to put the GA code  "immediately before" the </HEAD> tag...

And if so what can I do? It is an Administrator form so I have no other control whatsoever... Shall I open an bug report?

Any comments will be greatly appreciated.

Best regards,

-- joão

In reply to Joao Freitas

Re: Moodle and Google Analytics

by Leticia Dark-rose -

Hello All,

I have been using Moodle Analytics for about 6 months and in the last 2 it has stopped collecting statistics. I did have a migration to a different server, however these are the only things I know, and i'm running out of answers as to what has happened.

Moodle Analytics worked when:

  1. The following code was used (id is now **):
<!-- MoodleAnalytics --> <script type="text/javascript"> var _paq = _paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//app.moodleanalytics.com/"; _paq.push(['setTrackerUrl', u+'analytics.php']); _paq.push(['setSiteId', ***]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'analytics.js.php'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//app.moodleanalytics.com/analytics.php?idsite=***" style="border:0;" alt="" /></p></noscript> <!-- End MoodleAnalytics Code -->
  1. Code was placed in Site Administration > Appearance >Additional HTML in the <BODY> tag - "Before the BODY is closed" section.

Now it's broken:

  1. I know that URL has moved from HTTP:// to HTTPS:/
  2. Several other errors 'database write permissions are occurring
  3. This has occurred on my DEV and UAT environments
  4. It is currently sitting internally ONLY (i.e. behind the firewall)
  5. IT have introduced a Microsoft 365 single compulsory account which must be logged into to access SITE ADMIN menu (could this be blocking it)?

Could anyone please provide assistance?


Thanks

Leticia smile 

In reply to Leticia Dark-rose

Re: Moodle and Google Analytics

by Leticia Dark-rose -

Curious....

I managed to install Google Analytics in the Header for both DEV and UAT. Dev is now recording, however UAT is still not.

Any ideas?

In reply to Leticia Dark-rose

Re: Moodle and Google Analytics

by James McLean -

I had written out a few ideas, but thought I should go to the URL to try it myself. When your local site is HTTPS, the URL structure of their code included in your page allows the request to be made via HTTPS - and in this case their HTTPS certificate is rejected by Chrome. There could be something fishy going on, but it's more likely their environment is mis-configured.

Do you have HTTPS on both of your Dev and UAT environments?

Example link:
https://app.moodleanalytics.com/analytics.php?idsite=1234


Additionally, the certificate is 2 years expired:


So, it's probably not you - it's them.