Getting started with Google Analytics and SEO

Now that we have our blog and apps up and running, we are curious to see if anybody is visiting our sites.

Attention: The following is based on the new GA4.

You head over to marketingplatform.google.com and sign into the Google Marketing Platform.

Again there is some new terminology that we have to get familiar with.

  • Organization
  • Accounts
  • Properties

An organization can have multiple accounts that have multiple properties.

In my simple case, I have one organization and one account named the same: My company name.

Then I have one property per website. Think of Property as a building people are visiting.

Properties

Google Analytics is about analyzing who is visiting your property and present you with these insights.

Like how many visitors do you have per minutes and which countries do they come from. And much more.

When you create a Property, you specify

  • Property name
  • Reporting time zone (choose your local time)
  • Currency (choose your local currency)

Then you get

  • a Stream ID. A number
  • a Measurement ID. Looks like this G-XXXXXXXXXX

Then you can copy some JavaScrip code. You will need this in a minute. See below.

Updating the <head> tag

On your website or webapp you have to insert two things in the <head> tag.

First find where the <head> tag is.

Jekyll Blog

In a Jekyll project, look in the _includes folder and open the file head.html and insert the following line after the meta tags in the beginning of the file.


<link rel="canonical" href="{{ site.url }}{{ page.url | replace:'index.html','' }}">

Then check the _config.yml file in the root of your project.

You should have the jekyll-seo-tag plugin and a permalink.

plugins:
  - jekyll-feed
  - jekyll-katex
  - jemoji
  - jekyll-seo-tag
permalink: /:categories/:year/:month/:day/:title:output_ext

jekyllrb.com/docs/permalinks/

Ruby on Rails App

In a Ruby on Rails app, look in the app/views/layouts folder and open the file application.html.erb and insert the following line after the meta tags in the beginning of the file.

<link rel="canonical" href="https://www.example.com">

Google tag (gtag.js)

In both Jekyll and Ruby on Rails, we have to insert the Google tag in the <head> element. Please place it just before the </head>.

In the following replace G-XXXXXXXXXX with the Measurement ID for your property. Notice that it are two places and they have to be identical.

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX');
</script>   

The above code is provided by Google Analytics when you create the property. Once you have created the property and published your changes to the web, use the Test button in Google Analytics to see that it works.

Test

Visit your website and see in Google Analytics that you have had your fist visit.

If something is not working, try inspecting your website and check that you can find the Measurement ID in the header of the page.

Further readings

Though the above instructions got you started, you have to dive further into the subject.

Jekyll and SEO

This article helped me.

A Beginner’s Guide to SEO optimization in a Jekyll static website

Jekyll has a good tutorial. Look for SEO on this page:

jekyllrb.com/docs/step-by-step/10-deployment

Alternatives to Google Analytics

If you don’t want to use Google Analytics, there are alternatives that you might want to consider.

One of them is plausible.io.