Skip to content

Google Analytics 4 Conversion Tracking

Sesamy integrates with Google Analytics 4 (GA4) Measurement Protocol to send purchase events directly to your GA4 property, enabling accurate conversion tracking and revenue attribution.

Overview

The Google Analytics 4 Measurement Protocol allows you to send events directly from your server to Google Analytics. This provides reliable, server-side tracking that complements browser-based tracking for a complete view of your conversions.

Benefits:

  • Accurate revenue and conversion tracking
  • Server-side tracking immune to ad blockers
  • Enhanced ecommerce reporting
  • Better attribution for marketing campaigns
  • Reliable data for optimization

Learn more: Google Analytics 4 Measurement Protocol

Getting Started

Prerequisites

  1. An active Google Analytics 4 property
  2. Admin access to your GA4 property
  3. A data stream configured for your website

Setup Process

Step 1: Create an API Secret

  1. Sign in to Google Analytics
  2. Click Admin (gear icon in the bottom left)
  3. In the Property column, select Data Streams
  4. Click on your web data stream
  5. Scroll down to Measurement Protocol API secrets
  6. Click Create
  7. Enter a nickname for the secret (e.g., "Sesamy Integration")
  8. Click Create
  9. Copy the generated Secret value

Important

Copy the secret value immediately after creation. You won't be able to see it again later.

Step 2: Find Your Measurement ID

While still viewing your data stream settings:

  1. Look for Measurement ID at the top of the stream details
  2. It will be in the format G-XXXXXXXXXX
  3. Copy this ID

Step 3: Provide Credentials to Sesamy

Send the following information to your Sesamy account manager:

  • API Secret: The secret value you generated
  • Measurement ID: Your stream's measurement ID (G-XXXXXXXXXX)

Your account manager will configure the integration for you.

Events & Data

Purchase Event

Sesamy automatically sends a purchase event to Google Analytics 4 immediately after a transaction is completed on your platform.

Data Payload

The following data is included in each purchase event:

ParameterDescriptionExample
currencyThe currency used for the transaction"USD", "EUR", "SEK"
valueThe total value of the transaction99.99
taxThe tax amount for the transaction19.99
transaction_idUnique checkout ID for the purchase"checkout_abc123"
couponThe coupon code if one was used"SAVE20"
itemsArray of purchased items (see below)[...]
client_idGoogle Analytics client identifier"123456789.1234567890"

Items Array

Each item in the items array includes:

FieldDescriptionSource
item_idThe product's SKUProduct SKU from your catalog
item_nameThe product titleProduct title
item_variantThe purchase option nameE.g., "Monthly", "Annual"
quantityNumber of items purchasedTypically 1 for subscriptions
pricePrice per itemItem price

Example payload:

json
{
  "client_id": "123456789.1234567890",
  "events": [
    {
      "name": "purchase",
      "params": {
        "currency": "SEK",
        "value": 99.0,
        "tax": 19.8,
        "transaction_id": "checkout_abc123",
        "coupon": "WELCOME10",
        "items": [
          {
            "item_id": "premium-monthly",
            "item_name": "Premium Subscription",
            "item_variant": "Monthly",
            "quantity": 1,
            "price": 99.0
          }
        ]
      }
    }
  ]
}

Client ID Tracking

Automatic Tracking

The client_id parameter is crucial for connecting server-side events with user sessions in GA4.

Automatic capture when using:

  • Sesamy.js library
  • Sesamy web components

When checkout generation happens via Sesamy.js and our web components, the _ga parameter is automatically captured from the Google Analytics cookie and passed to the checkout process.

Custom Implementation

If you're using a custom implementation without Sesamy.js:

  1. Extract the GA Client ID from the _ga cookie in the user's browser

    javascript
    // The _ga cookie format: GA1.2.123456789.1234567890
    // Extract the last two parts: 123456789.1234567890
    const gaCookie = document.cookie.split('; ').find((row) => row.startsWith('_ga='));
    
    if (gaCookie) {
      const parts = gaCookie.split('.');
      const clientId = `${parts[2]}.${parts[3]}`;
      // Pass this as _ga parameter to checkout
    }
  2. Pass the _ga parameter when creating a checkout:

    https://checkout.sesamy.com/?_ga=123456789.1234567890
  3. Sesamy will use this value as the client_id when sending events to GA4

TIP

Without the _ga parameter, a random client_id will be generated, which means the purchase event won't be connected to the user's browsing session in GA4 reports.

Integration Features

Server-Side Tracking

All events are sent server-to-server from Sesamy's backend to Google Analytics 4:

  • Reliable delivery: Events are sent even if the user closes their browser
  • Ad blocker resistant: Server-side tracking bypasses browser-based blockers
  • Better accuracy: Ensures all purchases are tracked
  • Privacy compliant: Server-side tracking can be configured to respect user privacy preferences

Enhanced Ecommerce

Purchase events follow GA4's ecommerce event schema, enabling:

  • Revenue reporting in GA4 ecommerce reports
  • Product performance analysis
  • Purchase funnel visualization
  • Marketing attribution

Monitoring & Verification

Test Your Integration

After setup is complete:

  1. Make a test purchase on your platform
  2. Go to Google Analytics
  3. Navigate to Reports > Realtime
  4. Look for the purchase event in the real-time event stream
  5. Verify the event parameters and revenue values

DebugView

For detailed testing, use GA4's DebugView:

  1. In Google Analytics, go to Configure > DebugView
  2. Make a test purchase
  3. View the detailed event parameters and validation

Delay in Reports

While events appear in Realtime and DebugView immediately, they may take 24-48 hours to appear in standard reports.

Verify in Reports

After 24-48 hours, check:

  1. Monetization Overview: Reports > Monetization > Overview
  2. Ecommerce Purchases: Reports > Monetization > Ecommerce purchases
  3. Purchase Event: Reports > Engagement > Events (filter for "purchase")

Event Deduplication

If you're also using browser-side GA4 tracking (gtag.js or Google Tag Manager), ensure events are deduplicated:

  • Each purchase event should include a unique transaction_id
  • GA4 automatically deduplicates events with the same transaction_id
  • Sesamy uses the checkout ID as the transaction_id for this purpose

Troubleshooting

Events Not Appearing

If events aren't showing up in GA4:

  1. Check Realtime reports first (not standard reports)
  2. Verify your credentials:
    • Measurement ID is correct
    • API Secret is valid
    • API Secret hasn't been deleted or regenerated
  3. Test with DebugView for more detailed error information
  4. Wait 24-48 hours for events to appear in standard reports

Missing Client ID Connection

If purchases aren't connecting to user sessions:

  1. Verify the _ga parameter is being passed to checkout
  2. Check that the GA cookie exists on your site
  3. Ensure GA4 is installed and working on your website
  4. Test with browser developer tools to see cookie values

Revenue Not Showing

If events appear but revenue is zero or missing:

  1. Verify the value parameter is being sent with purchase events
  2. Check that currency codes are valid (ISO 4217 format)
  3. Ensure items array includes price information
  4. Review the event in DebugView for parameter validation errors

Best Practices

  1. Use Both Client and Server Tracking: Implement browser-side GA4 tracking alongside Measurement Protocol for complete coverage
  2. Pass the GA Client ID: Always include the _ga parameter for proper attribution
  3. Test Thoroughly: Use DebugView to verify all parameters are correct
  4. Monitor Regularly: Check reports weekly to ensure tracking is working
  5. Document Your Setup: Keep a record of your Measurement ID and which API Secret you're using
  6. Respect Privacy: Configure tracking in compliance with GDPR and privacy regulations

Data Privacy & Compliance

GDPR Considerations

  • Server-side tracking should respect user consent preferences
  • Ensure you have proper consent before tracking purchases
  • Consider implementing consent mode for GA4

IP Anonymization

GA4 automatically anonymizes IP addresses in compliance with privacy regulations.

Support

For assistance with Google Analytics 4 integration:

Released under the MIT License.