General developer forum
Moodle and Google Analytics
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.
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?
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 .
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.
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.
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?
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.
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...
Allow specific user roles to be excluded.
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?
Have you made any progress with the ability to distinguish between staff, visitors & student visits? Would be so useful to have.
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!
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.
The block add in doesn't work as stated and it seems to be abandoned.
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.
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.
In 2.0 go to Site Administration > Appearance > Additional HTML and copy the Tracking Code from Google Analytics into the 'Within Header' box.
is there any 'google analytics' block ??
i found something like this
but that is for 1.9
pls help me is any of you knows
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 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.
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
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!
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.
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?
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,
- When checking on GA Admin page it says it is not installed and hence it does not do any stats
...Could this meta tag be the culprit? They do say to put the GA code "immediately before" the </HEAD> tag...
ga('create', 'UA-99999999-1', 'auto');
</script> <meta name="viewport" content="width=device-width, initial-scale=1.0">
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.
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:
- The following code was used (id is now **):
- Code was placed in Site Administration > Appearance >Additional HTML in the <BODY> tag - "Before the BODY is closed" section.
Now it's broken:
- I know that URL has moved from HTTP:// to HTTPS:/
- Several other errors 'database write permissions are occurring
- This has occurred on my DEV and UAT environments
- It is currently sitting internally ONLY (i.e. behind the firewall)
- 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?
I managed to install Google Analytics in the Header for both DEV and UAT. Dev is now recording, however UAT is still not.
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?
Additionally, the certificate is 2 years expired:
So, it's probably not you - it's them.