Google Analytics 4 Event Tracking | OpsBlu Docs

Google Analytics 4 Event Tracking

How to implement custom event tracking in Google Analytics 4. Covers event naming conventions, required and optional parameters, ecommerce events.

Overview

Google Analytics 4 uses an event-based data model where every interaction is captured as an event with associated parameters. Unlike Universal Analytics' Category/Action/Label structure, GA4 events are flat with flexible parameter attachments, offering greater analytical flexibility.

Event Types in GA4

Automatically Collected Events

GA4 captures these without configuration:

Event Description
first_visit First time a user visits
session_start New session begins
page_view Page loads (enhanced measurement)
scroll 90% scroll depth reached
click Outbound link clicks
view_search_results Site search performed
file_download File download initiated
video_start, video_progress, video_complete YouTube video engagement

Enhanced Measurement Events

Enabled in data stream settings:

Event Trigger
page_view History state changes (SPAs)
scroll Vertical scroll reaches 90%
outbound_click Link to external domain clicked
site_search URL contains search query parameter
file_download Common file extensions clicked
form_start Form interaction begins
form_submit Form submission

Google's predefined events for common use cases:

Category Events
Ecommerce view_item_list, view_item, add_to_cart, remove_from_cart, view_cart, begin_checkout, add_shipping_info, add_payment_info, purchase, refund
Lead Gen generate_lead, sign_up, login
Content share, search, select_content, view_promotion, select_promotion
Engagement earn_virtual_currency, spend_virtual_currency, tutorial_begin, tutorial_complete, level_up, unlock_achievement

Custom Events

Create events for business-specific interactions:

Event Use Case
newsletter_signup Email list subscription
feature_used Specific feature engagement
pricing_viewed Pricing page interaction
demo_requested Demo form submission
support_chat_started Support interaction

Event Implementation

gtag.js Syntax

gtag('event', 'event_name', {
  'parameter1': 'value1',
  'parameter2': 'value2'
});

Google Tag Manager

  1. Create a GA4 Event tag
  2. Set the Configuration Tag to your GA4 config
  3. Enter the Event Name
  4. Add Event Parameters from GTM variables
  5. Set appropriate trigger

Data Layer Push

dataLayer.push({
  'event': 'add_to_cart',
  'ecommerce': {
    'currency': 'USD',
    'value': 79.99,
    'items': [{
      'item_id': 'SKU-12345',
      'item_name': 'Wireless Headphones',
      'price': 79.99,
      'quantity': 1
    }]
  }
});

Core Events Catalog

Ecommerce Events

view_item_list

gtag('event', 'view_item_list', {
  item_list_id: 'category_electronics',
  item_list_name: 'Electronics',
  items: [
    {
      item_id: 'SKU-12345',
      item_name: 'Wireless Headphones',
      index: 0,
      price: 79.99
    },
    {
      item_id: 'SKU-67890',
      item_name: 'Bluetooth Speaker',
      index: 1,
      price: 49.99
    }
  ]
});

add_to_cart

gtag('event', 'add_to_cart', {
  currency: 'USD',
  value: 79.99,
  items: [{
    item_id: 'SKU-12345',
    item_name: 'Wireless Headphones',
    item_brand: 'AudioTech',
    item_category: 'Electronics',
    price: 79.99,
    quantity: 1
  }]
});

purchase

gtag('event', 'purchase', {
  transaction_id: 'ORD-98765',
  value: 156.96,
  tax: 8.00,
  shipping: 5.99,
  currency: 'USD',
  coupon: 'SUMMER10',
  items: [{
    item_id: 'SKU-12345',
    item_name: 'Wireless Headphones',
    price: 79.99,
    quantity: 1,
    coupon: 'SUMMER10'
  }]
});

Engagement Events

scroll_depth (custom)

// Track granular scroll milestones
gtag('event', 'scroll_depth', {
  percent_scrolled: 50,
  page_location: window.location.href
});

video_engagement (custom)

gtag('event', 'video_engagement', {
  video_title: 'Product Demo',
  video_provider: 'vimeo',
  video_percent: 75,
  video_current_time: 120,
  video_duration: 160
});

time_on_page (custom)

gtag('event', 'engaged_time', {
  engagement_time_msec: 60000,
  page_location: window.location.href
});

Lead Generation Events

generate_lead

gtag('event', 'generate_lead', {
  currency: 'USD',
  value: 100,  // Lead value
  lead_source: 'contact_form'
});

sign_up

gtag('event', 'sign_up', {
  method: 'email'  // or 'google', 'facebook'
});

Search Events

gtag('event', 'search', {
  search_term: 'wireless headphones',
  search_results_count: 24
});

Event Parameters

Standard Parameters

Parameter Type Description
currency string ISO 4217 currency code
value number Monetary value
items array Array of item objects
method string Auth/share method
content_type string Type of content
item_id string Unique item identifier

Custom Parameters

GA4 allows up to 25 custom event parameters per event:

gtag('event', 'custom_event', {
  custom_param_1: 'value1',
  custom_param_2: 123,
  custom_param_3: true
});

Register custom parameters as dimensions/metrics in GA4:

  1. Go to Admin > Custom definitions
  2. Click Create custom dimension or Create custom metric
  3. Map the parameter name and scope

User Properties

Set persistent user-level attributes:

gtag('set', 'user_properties', {
  customer_tier: 'premium',
  subscription_status: 'active',
  lifetime_value: 1500
});

Naming Conventions

Event Names

  • Use snake_case exclusively
  • Maximum 40 characters
  • Start with a letter
  • Avoid reserved prefixes (ga_, google_, firebase_)
  • Be descriptive but concise

Good examples:

  • newsletter_subscribe
  • pricing_table_click
  • feature_onboarding_complete

Avoid:

  • newsletterSubscribe (camelCase)
  • Newsletter Subscribe (spaces)
  • ga_custom_event (reserved prefix)

Parameter Names

  • Use snake_case
  • Maximum 40 characters
  • Be consistent across events
  • Match GA4 reserved parameter names where applicable

Conversion Configuration

Mark important events as conversions:

  1. Go to Admin > Events
  2. Toggle the Mark as conversion switch
  3. Or go to Admin > Conversions > New conversion event

Conversion events unlock:

  • Google Ads optimization
  • Attribution analysis
  • Funnel reporting

Event Limits and Quotas

Limit Value
Unique event names 500 per property
Event parameters per event 25
User properties 25
Parameter name length 40 characters
Parameter value length 100 characters
Events per session No hard limit

QA and Validation

DebugView

  1. Enable debug mode:

    • GTM Preview Mode (automatic)
    • GA Debugger extension
    • URL parameter: ?debug_mode=true
    • gtag: gtag('config', 'G-XXXXX', { debug_mode: true })
  2. Open GA4 > Admin > DebugView

  3. Trigger events on your site

  4. Verify events appear with correct parameters

Real-Time Reports

  1. Open GA4 > Reports > Real-time
  2. Check Event count by Event name
  3. Click events to view parameters
  4. Verify parameter values are correct

Validation Checklist

Check How to Validate
Event fires on interaction DebugView shows event immediately
Parameters populated Click event in DebugView to see params
Ecommerce items array Check items in event parameters
No duplicate events Single event per interaction
Consent respected No events fire when denied
Currency format ISO 4217 (USD not $)
Value is numeric No strings or formatted values

Common Issues

Symptom Cause Solution
Event not appearing Consent blocking Check consent state
Missing parameters GTM variable undefined Verify data layer push
Duplicate events Multiple triggers firing Review GTM trigger conditions
Items array empty Ecommerce data layer incorrect Validate data layer structure
Event name not recognized Typo or wrong case Match exact GA4 event names

Attribution Considerations

Engagement Time

GA4 uses engagement_time_msec for session quality:

// Custom engaged time tracking
let startTime = Date.now();
window.addEventListener('beforeunload', () => {
  const engagedTime = Date.now() - startTime;
  navigator.sendBeacon('/analytics', JSON.stringify({
    event: 'page_engagement',
    engagement_time_msec: engagedTime
  }));
});

Session Attribution

Events inherit session-level attribution from session_start. Ensure campaign parameters persist through the user journey: