TheByteDungeon

TheByteDungeon is a personal tech blog where I document my thoughts, explore technical challenges, and reinforce my knowledge.

Home Posts Projects View on GitHub
27 August 2024

Using Google Analytics

I’ve always been curious how much data appears on Google Analytics and especially what conclusion Google makes from it (if any).

:bar_chart: Getting started

Enabling analytics on a site is very easy. All we have to do is to create a “company” and and by including a bit of javascript code we are good to go:

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

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

T096ZRKQHL is my unique ID, which will connect any readers to my Google “company”. This is assuming the reader does not block javascript or blocks trackers.:v:

Preventing data from being sent to Google analytics

There are a number of possibilites, some of them include:

What happens in the background?

Looking at the https://www.googletagmanager.com/gtag/js?id=G-T096ZRKQHL URL which users access, it load a javascript file:

$ wc -l js\?id=G-T096ZRKQHL
779 js?id=G-T096ZRKQHL
# 
$ wc -c js\?id=G-T096ZRKQHL
315180 js?id=G-T096ZRKQHL

315k characters :tada:

support.google.co tells us what they are doing:

Every time a user visits a webpage, the tracking code will collect pseudonymous information about how that user interacted with the page. The measurement code will also collect information from the browser like the language setting, the type of browser (such as Chrome or Safari), and the device and operating system on which the browser is running. It can even collect the “traffic source,” which is what brought users to the site in the first place. This might be a search engine, an advertisement they clicked on, or an email marketing campaign.

Apparently the new version of Google analytics don’t relay mainly on cookies, but use some “event based tracking” focusing on user clicks. They must still reply somewhat om the cookies but it seem like the trend is pointing downwards.

Data in analytics

So how does it look? Well, of course there ain’t much data as of now (and it will be a pretty flat graph in the forseeable future as well :wink: ). Let’s head over to analytics.google.com.

There are data on location, interest, sex, age and language. We can also get data on “user engagement”, i.e. how long did the user stay and what did she view. We can customize this, but this is the default view: google_analytics google_analytics

Woh, some fun tech data! Platform, screen resolution, browser etc. :computer: google_analytics

Conclusion

It was very easy to configure and I can see the value such a service can bring when you are actually selling a product or where there a lot of site viewers. This is definitely not a service I’ll need to monitor going forward. :wink:

tags: google