Setting Up Google Analytics GA4 to Track Page Views with Custom Variable Macro

Setting Up Google Analytics GA4 to Track Page Views with Custom Variable Macro

Overview

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.

Step-by-Step Instructions

1. Insert GA4 Tracking Code in SoCast

  1. Log in to SoCast:

    • Navigate to the SoCast platform and log in with your credentials.

  2. Access Website Settings:

    • Go to Website > Website Settings.

  3. Locate Custom Footer HTML:

    • Find the setting called "Custom Footer HTML".

  4. 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.

2. Verify Implementation

  1. Publish and Access a Blog Page:

    • Publish the changes and open a blog page on your website.

  2. 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.

3. Set Up a Custom Dimension in GA4

  1. Log in to Google Analytics:

    • Access your GA4 property by logging in to Google Analytics.

  2. Navigate to Admin Settings:

    • In the bottom left corner, click on Admin.

  3. 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.

4. Create a Report in GA4

  1. Go to Explore:

    • From the left-hand menu, select Explore.

  2. Create a New Exploration:

    • Click on Blank.

  3. Set Up the Exploration Report:

    • Rename your exploration if needed (e.g., "Blog Category Page Views").

  4. 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.

  5. Configure the Table:

    • Drag the Blog Category dimension to the Rows section.

    • Drag the Event Count metric to the Values section.

  6. Apply Filters (Optional):

    • If you want to filter by specific criteria, use the Filters section to add relevant filters.

  7. 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.


    • Related Articles

    • How To Read The Omnichannel Engagement Report

      Below is a list of all column titles in the Omnichannel Engagement Report and how to analyze them. You can find their definition by hovering over the "?" located under each column title. This report is under Analytics > Omnichannel Engagement Report ...
    • Comparing Blog View Counters and Google Analytics

      In some cases, there might be a discrepancy between what you see in the blog view counter and Google Analytics. We understand that having accurate traffic data is crucial for your analysis and decision-making processes. Here’s a detailed explanation ...
    • What Does Bounce Rate Mean in Google Analytics?

      In Google Analytics, bounce rate refers to the percentage of single-page sessions on your website. It essentially shows the proportion of visitors who navigate away from your site after viewing only one page, without interacting further with the ...
    • How Do I Access Analytics In SoCast?

      Note: This report includes syndicated blogs or RSS syndicated blogs within the data. Currently Company Admins can access an Executive Report of analytics for all of their stations/accounts under Admin > Executive Report. This report can be found ...