This guide explains how to set up Google Analytics GA4 to track page view events with a custom variable macro %socast.blog.categories%
, which contains the blog category name. The setup involves inserting the GA4 tracking code with the custom variable macro into the SoCast platform and configuring a report in Google Analytics to view page views by blog category.
Log in to SoCast:
Navigate to the SoCast platform and log in with your credentials.
Access Website Settings:
Go to Website > Website Settings
.
Locate Custom Footer HTML:
Find the setting called "Custom Footer HTML".
Insert GA4 Tracking Code with Custom Variable Macro:
Copy the following GA4 tracking code snippet, replacing G-XXXXXXX
with your GA4 Measurement ID:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="<https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX', {
'custom_map': {'dimension1': 'blog_category'}
});
// Capture the blog category
gtag('event', 'page_view', {
'blog_category': '%socast.blog.categories%'
});
</script>
Paste the code into the "Custom Footer HTML" section.
Save the changes.
Publish and Access a Blog Page:
Publish the changes and open a blog page on your website.
Use Google Tag Assistant:
Install the Google Tag Assistant Chrome extension and check that the GA4 tag is firing correctly and capturing the blog_category
parameter.
Log in to Google Analytics:
Access your GA4 property by logging in to Google Analytics.
Navigate to Admin Settings:
In the bottom left corner, click on Admin
.
Set Up Custom Dimensions:
Under the Property
column, click on Custom Definitions
.
Click on Create Custom Dimensions
.
Fill in the following details:
Dimension name: Blog Category
Scope: Event
Description: Tracking blog category names
Event parameter: blog_category
Click on Save
.
Go to Explore:
From the left-hand menu, select Explore
.
Create a New Exploration:
Click on Blank
.
Set Up the Exploration Report:
Rename your exploration if needed (e.g., "Blog Category Page Views").
Add Dimensions and Metrics:
Click on the +
icon next to Dimensions and select Blog Category
.
Click on the +
icon next to Metrics and select Event Count
.
Configure the Table:
Drag the Blog Category
dimension to the Rows
section.
Drag the Event Count
metric to the Values
section.
Apply Filters (Optional):
If you want to filter by specific criteria, use the Filters
section to add relevant filters.
Save and Analyze:
Save your exploration and analyze the page views by blog category.
By following these steps, you can successfully set up Google Analytics GA4 to track page views with the custom variable macro %socast.blog.categories%
. You will then be able to create detailed reports in GA4 to analyze the performance of different blog categories. This setup provides valuable insights into the engagement and popularity of various blog topics, aiding in content strategy and optimization.