Skip to content

Google Analytics

Carrie Wright edited this page Jul 20, 2023 · 12 revisions

If you would like to add Google Analytics to track traffic to your course, you can do the following:

  1. Get a Google Analytics account (if you do not already have one): https://analytics.google.com/analytics

Google Analytics account setup

Note that in creating an account you will need to agree to some terms. Currently it is free to get Google analytics data as long as your course does not exceed a very high user rate. Check to make sure that the terms work for you

Google Analytics terms

  1. If you already have an account or navigated away from where you started - Go to the Admin tab (lower left button that looks like a gear)

  2. Set up a new property (fill out name and details, select options about tracking traffic for how you intend to use Google Analytics)

Google Analytics Property creation

Google Analytics Property

Google Analytics Property choices

  1. Add a stream to your property, choose the Web option.

Google Analytics stream options

  1. Fill in your stream information with the link for your course (note you may need to remove https as this is part of a pull down menu to the left of where you paste your link)

Google Analytics stream

Google Analytics stream

  1. On the resulting page you will see a Measurement ID. Copy this ID and paste it in the GA_Script.Rhtml file in the template replacing the fields that say {MeasurementID} including the curly brackets.

  1. Modify the _output.yml file so that the line that starts with before body: is changed to include brackets around the GA_script.Rhtml file before a comma and the name of the hero image html file (which should already be listed). For example, like this: before_body: [GA_Script.Rhtml, assets/big-image-itcr.html] or this: before_body: [GA_Script.Rhtml, assets/big-image.html]

  2. Rerender your course by making a change to one of your chapter RMD files in a pull request and pushing and merging the pull request. This will cause new html files to be made for each chapter in the docs folder. The Google Analytics code should now be in each of the html files - you can check by searching for Google Analytics.

  3. Go back to Google Analytics and log in if you need to.

  4. Check on the Reports button on the top of the far left icon menu. The icon looks like a bar chart. If you open up a browser window to your hosted course online, then you should see yourself as 1 user in the last 30 minutes.

Google Analytics Reports

Check Google Analytics

  1. Enjoy the data about how people are using your course!
Clone this wiki locally