Enhancing Revenue Tracking with Google Tag Manager and GA4

Jul 17, 2024

Enhancing Revenue Tracking with Google Tag Manager and GA4

Introduction

  • Topic: Tracking site search with Google Analytics 4 (GA4) and attributing revenue to search terms
  • Tools Used: Google Tag Manager (GTM) and GA4
  • Objective: Configure GA4 to attribute revenue from purchases to specific site search terms

GA4 Setup

  • GA4 doesn't automatically attribute revenue to search terms
  • Additional configuration is needed

Google Tag Manager Configuration

  • Demo Setup: Demo GTM container with one GA4 tag
  • Prerequisites: Basic knowledge of installing GA4 with GTM

Purchase Tracking Setup

  1. Purchase Event in Data Layer:
    • Ensure purchase data is pushed to the data layer upon purchase (fake product example)
    • Developer may be needed to modify the data layer code to include relevant info (e.g., product ID)
  2. Create Trigger for Purchase Event:
    • Go to Trigger Configuration > New > Custom Event Trigger
    • Name: purchase
    • Name the Trigger: purchase
  3. Create GA4 Tag for Purchase Event:
    • Tags > New > Tag Configuration > GA4 Event
    • Insert Measurement ID (found in GA4 admin section)
    • Event Name: purchase
    • More Settings > E-commerce Data > Data Source: Data Layer
    • Minimum required parameters (currency, value, transaction ID, items with name, id, quantity, price)
    • Trigger: Custom purchase trigger
    • Name the Tag: purchase

Site Search Keyword Configuration

  • Objective: Store site search keyword in a cookie and send it with the purchase event

Creating a Variable

  1. Extract Keyword from URL:
    • Variable Configuration > New > URL
    • Variable Type: Query
    • Query Key: Parameter after ? in URL (e.g., s)
    • Name the Variable
  2. Test the Variable:
    • Preview and test if the variable extracts the keyword from the search

Storing Keyword in a Cookie

  1. Create and Configure Cookie Tag:
    • Tags > New > Tag Configuration > Custom HTML
    • Paste and modify the cookie setting code (name and value)
    • Adjust cookie expiration (1 day recommended)
    • Trigger: Page view where the URL contains the search keyword
    • Name the Tag: chtml set cookie gdm search term
  2. Test Cookie Tag:
    • Verify that the cookie tag fires correctly
    • Check the cookie in the developer tools (Application > Cookies)

Sending Keyword with Purchase Data

  1. Update GA4 Purchase Tag:
    • Add event parameter: search_term
    • Create new variable for cookie (First Party Cookie, name matching cookie name)
    • Save and test the tag
  2. Verify in GA Debug View:
    • Ensure purchase event includes the search term

Reporting in GA4

  1. Create Exploration Report:
    • GA4 > Explore > Blank
    • Add Dimensions: Search Term
    • Add Metrics: Purchase Revenue
    • Analyze revenue per keyword

Conclusion

  • Importance of combining search keywords with purchase events
  • Encouragement to like the video and subscribe for more content

Additional Resources

  • Look for links and tutorials in the video description for more in-depth guidance
  • Documentation on GA4 data layers and GTM cookie setup