Google Analytics with Jekyll

To answer your question, yes, you need that script on every page.

To start you off on the right path:

  1. Visit Google Tag Manager Quick Start Guide
  2. Notice that there are 2 scripts to install on every page you want tracked
    a. the JavaScript excerpt like your current script you have above (although it looks like you’re missing a few items [see their example], this is to be located in the
    b. The iframe that’s supposed to be located in the
  3. Now, once you have the correct scripts (visit your GTag manager dashboard and copy and paste both script), you have a decision to make, do you want to manually add them to every page, or you want to create 2 partials (I call them layoutPartials, but Jekyll refers to them as includes)? Let’s be efficient, and choose the includes path.
  4. Create 2 files in includes:
    a. src/_includes/GoogleTagManager_head.liquid
    b. src/_includes/GoogleTagManager_body.liquid
  5. In GoogleTagManager_head.liquid add the JavaScript snippet from GTag manager dashboard
  6. In GoogleTagManager_body.liquid add the non-JavaScript code/iFrame snippet from GTag manager dashboard
  7. So, if you’re still with me (and I hope you still are =), it’s time for you to reference these in the layout file you are using for your blog (actually, if you have more than 1, add to all layout files).
    a. In the of your layout, {% include GoogleTagManager_head.liquid %}
    b. In the of your layout, {% include GoogleTagManager_body.liquid %}

Hoping this helps get all your pages tracking well! Give thumbs up if it helps :+1: so others can learn as well as mark as the answer..

All the best

2 Likes