Weeknotes #31
This week I configured Google Analytics 4 (GA4) for the Digital Culture Network website to pass additional data about our content. We can now report on content authors, publish dates, word counts and more. Here are the steps to set things up (with a little help from ChatGPT):
Customising Google Analytics 4
As the new financial year is approaching we wanted to set up some additional data collection about the Digital Culture Network website to understand what is working well.
We have sections of the site which serve different purposes, to report on these we usually filter by the page URL or page title. What we’re missing is information about when the content was created, how long it is and who wrote it.
With that in mind I looked at what data is available and how this can be passed to Google Analytics 4.
Extracting page data
We use the Yoast SEO plugin on our Wordpress website, this automatically places schema data into our page source code. For example, on my Getting started with Google Analytics 4 resource, the following schema data is available:
<script type="application/ld+json" class="yoast-schema-graph"> {"@context":"https://schema.org","@graph":[{"@type":"ScholarlyArticle","@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#article","isPartOf":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/"},"author":{"name":"James Akers","@id":"https://digitalculturenetwork.org.uk/#/schema/person/120ad6cdfdbc1fbedcef153fe745b141"},"headline":"Webinar recording – Getting started with Google Analytics 4","datePublished":"2023-02-24T10:02:28+00:00","dateModified":"2023-02-24T14:25:46+00:00","mainEntityOfPage":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/"},"wordCount":1598,"publisher":{"@id":"https://digitalculturenetwork.org.uk/#organization"},"image":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#primaryimage"},"thumbnailUrl":"https://digitalculturenetwork.org.uk/wp-content/uploads/2023/02/Webinar-Youtube-Thumbnail.png","articleSection":["The Fundamentals","Making the Most Out of Your Data"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/","url":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/","name":"Webinar recording - Getting started with Google Analytics 4 - Digital Culture Network","isPartOf":{"@id":"https://digitalculturenetwork.org.uk/#website"},"primaryImageOfPage":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#primaryimage"},"image":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#primaryimage"},"thumbnailUrl":"https://digitalculturenetwork.org.uk/wp-content/uploads/2023/02/Webinar-Youtube-Thumbnail.png","datePublished":"2023-02-24T10:02:28+00:00","dateModified":"2023-02-24T14:25:46+00:00","description":"A webinar for creative and culture organisations who wish to create, configure and install Google Analytics 4.","breadcrumb":{"@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#primaryimage","url":"https://digitalculturenetwork.org.uk/wp-content/uploads/2023/02/Webinar-Youtube-Thumbnail.png","contentUrl":"https://digitalculturenetwork.org.uk/wp-content/uploads/2023/02/Webinar-Youtube-Thumbnail.png","width":640,"height":360,"caption":"Getting started with Google Analytics 4 thumbnail"},{"@type":"BreadcrumbList","@id":"https://digitalculturenetwork.org.uk/knowledge/webinar-recording-getting-started-with-google-analytics-4/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Knowledge Hub","item":"https://digitalculturenetwork.org.uk/knowledge/"},{"@type":"ListItem","position":2,"name":"The Fundamentals","item":"https://digitalculturenetwork.org.uk/knowledge/category/the-fundamentals/"},{"@type":"ListItem","position":3,"name":"Webinar recording – Getting started with Google Analytics 4"}]},{"@type":"WebSite","@id":"https://digitalculturenetwork.org.uk/#website","url":"https://digitalculturenetwork.org.uk/","name":"Digital Culture Network","description":"Digital Skills For Arts & Culture","publisher":{"@id":"https://digitalculturenetwork.org.uk/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://digitalculturenetwork.org.uk/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https://digitalculturenetwork.org.uk/#organization","name":"Digital Culture Netwrok","url":"https://digitalculturenetwork.org.uk/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https://digitalculturenetwork.org.uk/#/schema/logo/image/","url":"https://digitalculturenetwork.org.uk/wp-content/uploads/2020/08/DCN_logo_Dark-Linear_CMYK-01-scaled.jpg","contentUrl":"https://digitalculturenetwork.org.uk/wp-content/uploads/2020/08/DCN_logo_Dark-Linear_CMYK-01-scaled.jpg","width":2560,"height":802,"caption":"Digital Culture Netwrok"},"image":{"@id":"https://digitalculturenetwork.org.uk/#/schema/logo/image/"},"sameAs":["https://www.youtube.com/digitalculturenetwork","https://twitter.com/ace_dcn"]},{"@type":"Person","@id":"https://digitalculturenetwork.org.uk/#/schema/person/120ad6cdfdbc1fbedcef153fe745b141","name":"James Akers","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https://digitalculturenetwork.org.uk/#/schema/person/image/","url":"https://digitalculturenetwork.org.uk/wp-content/uploads/2020/07/james-akers-profile-96x96.jpg","contentUrl":"https://digitalculturenetwork.org.uk/wp-content/uploads/2020/07/james-akers-profile-96x96.jpg","caption":"James Akers"}}]} </script>
This schema contains lots of information about the post, such as: author, datePublished, dateModified, and wordCount. We are able to use Google Tag Manager to pick up this data and pass it to Google Analytics 4 when the page loads.
“Surely you must be a JavaScript expert to do this! “
Nope. I used ChatGPT.
Question: If this is in the website head, how can I extract the author name into Google Tag Manager?
(I pasted the above schema code)
Answer:
I then asked it to amend the code to return “Digital Culture Network” if no author is found.
Wonderful! Over to Google Tag Manager, I created a new Variable and pasted the code in.
I did the same for the other bits of data I wanted to pass as well.
In our GA4 Configuration Tag I added new fields for the different parameters (always lowercase, with underscore for spaces). These will pick up the values from the variables and pass them to GA4 with every page view.
For the content_group parameter, I created a RegEx Table which matches what the page URL is and outputs the text I want. For example, if a user visits any page where the URL contains “events” then it will output “Events”. This will help us categorise the different sections of the site and filter our reports.
I have been more explicit for the News section as “news” would also match any URL with “newsletter” in it.
If you’d like to learn more about Regular Expressions, this article from Measure School is great and includes a cheat sheet.
Once these were set up I used the Preview mode in Google Tag Manager to test the data was coming through as expected and tweaked the code provided by ChatGPT to make it consistent.
Custom Definitions
The beauty of GA4 is it’s flexibility and how customised it can be. However, after you start passing new data into it you have to tell exactly what you want to get out again.
With each page view we are now passing the following parameters into GA4:
content_group
content_author
content_word_count
content_publish_year
content_publish_date
content_modified_date
estimated_reading_time
To use these in reports, we need to define each one and give them a name. We do this under Admin > Custom Definitions in GA4.
Clicking Create custom dimensions will open a new screen where you can give your new Dimension a name and match it to your event parameter. In the example below my Dimension is named “Author” and my Event parameter is “content_author”.
If data has been collecting for over 24 hours, you will be able to pick the Event parameter from the dropdown list. Otherwise, you can just enter it as text as you know what it is named already.
I repeated this for each of the new parameters. From this point inwards, whenever the Event parameter is passed as data into GA4, it will assign the Dimension name and be available in reports.
Reporting on new data
After 24 hours I could pick the new Dimensions to add to the exploration reports. Here I’m counting Views against Page Title, Author and Content group:
In Looker Studio I can dig deeper into the data. As we’re passing content_publish_date through, I can use the “Type” functionality to split out the data into publish quarter, month, and day if needed.
We can now see and filter data by the Content group, Author, Publish date, Estimated reading time and Word count. Not all of it is relevant, for example we don’t really need to know when the homepage was published, but when focusing of different areas of the website and using them alongside the other standard metrics, it will help us understand what content is working well.
Hopefully that gives a idea of the type of customisations you can do with Google Analytcis 4 and Tag Manager. We’ve used data from the Yoast SEO plugin but your website may be passing it through it different ways.
As ever, if you need help with any of this (and you work in the cultural sector in England) please get in touch for a free 1-2-1.