Commerce

Revenue attribution with GA4

Send chat events to Google Analytics 4 and compare revenue from shoppers who chatted with those who didn't.

The Octocom chat widget reports chat activity to Google Analytics 4, or GA4, and marks every visitor who sends a message. That shows you what your chat is worth, in two ways:

  • Chat engagement in GA4. See how many visitors open the chat and send messages, and build funnels from chat to purchase, alongside the rest of your traffic.
  • Revenue attribution in Octocom. Connect your GA4 property to Octocom to compare revenue, order value and conversion between shoppers who chatted and shoppers who didn't, in Metrics -> Sales.

Setup takes three steps:

  1. Make sure the widget's events reach GA4. With gtag.js this is automatic. With Google Tag Manager, add a few triggers and tags.
  2. Register the octocom_chatted user property as a custom dimension in GA4.
  3. Optionally, connect GA4 to Octocom to see the revenue split in your Octocom metrics.

GA4 and Octocom's own purchase tracking

Octocom also records purchases itself and links each one to the visitor who chatted: automatically for Shopify stores, and through browser session purchases for any other checkout, counting purchases within 7 days of a conversation. GA4 instead compares shoppers who ever chatted with those who didn't, so its totals run higher. When Octocom has no attributed revenue of its own for a view, Metrics -> Sales shows GA4's revenue instead.

Which setup do you have?

There are two common ways to install GA4:

MethodHow to identifySetup required
gtag.js (direct)You have a gtag.js script snippet on your siteNone: events appear automatically
Google Tag Manager (GTM)You have a GTM container script on your siteCreate triggers and tags in GTM

Not sure which one you have? Open your browser's developer console on your site and run:

// Check for gtag.js (direct)
!!document.querySelector('script[src*="gtag/js?id=G-"]');
// true = gtag.js is installed → events work automatically

// Check for GTM
!!document.querySelector('script[src*="gtm.js?id=GTM-"]');
// true = GTM is installed → you need to set up triggers

You can also check your site's HTML source:

  • A script loading from googletagmanager.com/gtag/js?id=G-XXXXXX means gtag.js.
  • A script loading from googletagmanager.com/gtm.js?id=GTM-XXXXXX means GTM.

What if I have both?

The widget sends each event one way, never both. If the page loads gtag.js for a GA4 property (a gtag/js?id=G- script and the gtag function), it sends the Option A events through gtag. Otherwise it pushes the Option B events to the dataLayer for GTM.

  • If gtag.js on the page is configured with the GA4 property where you want chat events, you're all set. Events go to the properties configured in gtag.js.
  • If you want the events in a GA4 property that gtag.js on the page doesn't send to, add that property to your gtag.js or Google tag configuration.
  • GTM triggers on the UserAction event (Option B) don't fire on pages with gtag.js, because the widget sends through gtag there instead.

Option A: gtag.js (automatic)

No setup required. The chat widget detects gtag.js on your page and sends events directly to GA4.

These events appear in your GA4 property under Reports -> Engagement -> Events:

Event nameWhen it fires
octocom_chat_openVisitor opens the chat widget
octocom_chat_closeVisitor closes the chat widget
octocom_chat_message_sentVisitor sends a message

All events include the parameter event_category: "Octocom Chat Widget".

Checking that events arrive

Events can take 24 to 48 hours to appear in standard GA4 reports. Open Reports -> Realtime to see them within seconds.

Next, register the chat user property.

Option B: Google Tag Manager

If GA4 is managed through GTM, create triggers and tags that forward the chat widget's events to GA4.

How it works

The chat widget pushes events to window.dataLayer in this format:

window.dataLayer.push({
  event: "UserAction",
  eventCategory: "Octocom Chat Widget",
  eventAction: "Open", // or "Close" / "Send Message"
});

The widget pushes these events when the page has no gtag.js for a GA4 property. GTM can listen for them and forward them to GA4, or to any other tag such as the Meta Pixel or LinkedIn.

Events reference

eventActionDescriptionWhen it fires
OpenChat window openedUser clicks the launcher or chat opens programmatically
CloseChat window closedUser clicks the close button
Send MessageMessage sentAny user message (first and subsequent)

Create Data Layer Variables

In GTM, create two Data Layer Variables so you can use the event data in your tags:

  1. Go to Variables -> New -> Data Layer Variable.
  2. Create eventCategory with Data Layer Variable Name eventCategory.
  3. Create eventAction with Data Layer Variable Name eventAction.

Create triggers

Create one trigger per event (or a single trigger for all).

Example: trigger for "Chat Open"

  1. Go to Triggers -> New.
  2. Name: Octocom - Chat Open
  3. Trigger type: Custom Event
  4. Event name: UserAction
  5. Fire on: Some Custom Events, with the conditions:
    • eventCategory equals Octocom Chat Widget
    • eventAction equals Open

Repeat for:

  • Octocom - Chat Close (eventAction = Close)
  • Octocom - Send Message (eventAction = Send Message)

Create GA4 Event tags

Example: GA4 tag for "chat_open"

  1. Go to Tags -> New.
  2. Name: GA4 - chat_open (Octocom)
  3. Tag type: Google Analytics: GA4 Event
  4. Measurement ID: your GA4 measurement ID (G-XXXXXXX).
  5. Event name: chat_open
  6. Optionally, add event parameters:
    • chat_category = {{eventCategory}}
    • chat_action = {{eventAction}}
  7. Trigger: Octocom - Chat Open

Repeat for:

  • GA4 - chat_close: event name chat_close, trigger Octocom - Chat Close
  • GA4 - chat_message_sent: event name chat_message_sent, trigger Octocom - Send Message

Forward the chat user property

Besides the three events above, the widget pushes a separate dataLayer event when a visitor first sends a message:

window.dataLayer.push({
  event: "octocom_user_property",
  octocom_chatted: "true",
});

This sets a user property (not an event parameter) called octocom_chatted. It persists across sessions and is what revenue attribution uses to separate shoppers who chatted from those who didn't. Without this step, the custom dimension you register below stays empty.

  1. Add a Data Layer Variable for the property value:

    • Variables -> New -> Data Layer Variable
    • Name: octocom_chatted
    • Data Layer Variable Name: octocom_chatted
  2. Add a trigger for the user-property push:

    • Triggers -> New
    • Name: Octocom - User Property
    • Trigger type: Custom Event
    • Event name: octocom_user_property
    • Fire on: All Custom Events
  3. Add a GA4 Event tag that sets the user property:

    • Tags -> New
    • Name: GA4 - octocom_chatted (Octocom)
    • Tag type: Google Analytics: GA4 Event
    • Measurement ID: your GA4 measurement ID (G-XXXXXXX).
    • Event name: octocom_user_property (any name works; this tag exists to carry the user property)
    • Under User Properties, add octocom_chatted = {{octocom_chatted}}
    • Trigger: Octocom - User Property

Publish

Publish your GTM container. Events and the user property start flowing to GA4.

Register the chat user property

The widget sets a user property called octocom_chatted on visitors who send a message. It persists across sessions, so you can compare conversion rates and revenue between visitors who used the chat and those who didn't.

GTM users

The widget pushes the property into the dataLayer, but it only reaches GA4 once you complete Forward the chat user property in Option B. Registering the custom dimension alone is not enough.

For GA4 to make the property available in reports and to Octocom, register it as a custom dimension (a one-time setup):

  1. In Google Analytics, go to Admin -> Custom definitions -> Custom dimensions.
  2. Click Create custom dimension.
  3. Configure it:
    • Dimension name: Octocom Chatted
    • Scope: User
    • User property: octocom_chatted
  4. Click Save.

Not retroactive

The custom dimension can take 24 to 48 hours to appear in reports. Data is collected from the moment you register it, not before.

Connect GA4 to Octocom

Connecting your GA4 property lets Octocom read your revenue data and show it in Metrics -> Sales, split between shoppers who chatted and shoppers who didn't. No code is required.

Before you start: your GA4 property must receive ecommerce purchase events (see below), and the octocom_chatted custom dimension must be registered.

Give Octocom read access in GA4

  1. Open Google Analytics and select the property that tracks your website and checkout.

  2. Click Admin (the gear icon in the bottom left).

  3. Under your property settings, click Property access management.

  4. Click + in the top right corner and select Add users.

  5. Enter this email address:

    octocom-ga4-reader@octocom.iam.gserviceaccount.com
  6. Set the role to Analyst. The Viewer role can't read revenue metrics.

  7. Click Add.

Find your GA4 Property ID

In GA4, go to Admin -> Property settings and copy the numeric Property ID, for example 251601386. This is not the G-XXXXXXX measurement ID.

Connect it in Octocom

In Octocom, open Settings -> Workspace -> Integrations -> Google Analytics 4, paste the number into GA4 Property ID and click Connect.

Octocom tests the connection before saving and tells you exactly what to fix if something is missing: the property ID can't be found, the service account has no access or only the Viewer role, or the octocom_chatted dimension isn't registered. Right after setup it may report that it is connected but hasn't seen any visitors who chatted yet. Revenue appears once shoppers chat and the widget reports them.

What Octocom reads

With Analyst access, Octocom runs read-only reports on your property. It reads daily totals of users, purchasers, purchase revenue and transactions, split by whether the visitor chatted (octocom_chatted). It does not read data about individual visitors, and it does not change your property's settings, events or tags.

Octocom refreshes these numbers every hour for the last 30 days up to yesterday, so purchases that GA4 reports late still correct earlier days. In Metrics -> Sales you can then compare:

  • revenue from shoppers who chatted and from those who didn't,
  • conversion rate for both groups,
  • average order value for both groups.

What if I don't have GA4 ecommerce tracking?

Revenue attribution needs your GA4 property to receive ecommerce events, specifically purchase. To check, go to Reports -> Monetization -> Ecommerce purchases in GA4. If you see data there, you're all set.

Shopify stores: ecommerce tracking is usually enabled through Shopify's built-in GA4 integration. If you don't see purchase data in GA4, make sure GA4 is connected in your Shopify admin under Online Store -> Preferences.

Other platforms (WooCommerce, Magento, custom and so on): ecommerce tracking is set up manually or through a plugin. Your platform may offer a GA4 integration: check its documentation for "GA4 ecommerce". With a custom checkout, your development team needs to implement the GA4 ecommerce events, specifically purchase.

Using events in GA4

Once events are flowing, through gtag.js or your GTM setup, here's how to use them.

Track chat engagement

  • Go to Reports -> Engagement -> Events to see event counts.
  • Example metric: chat engagement rate = (chat opens / page views) x 100.
  • Break it down by page, device or traffic source.

Build a conversation funnel

Use Explore -> Funnel exploration:

  1. Step 1: chat_open (or octocom_chat_open with gtag.js)
  2. Step 2: chat_message_sent (or octocom_chat_message_sent)
  3. Step 3: your main conversion (purchase, lead submission and so on)

This shows the drop-off between opening the chat, engaging and converting.

Mark as a key event

If you treat chat engagement as a micro-conversion, mark the chat event as a key event (GA4's name for a conversion):

  1. Go to Admin -> Data display -> Events.
  2. Find your chat event.
  3. Mark it as a key event.

Custom reports

Useful dimensions to combine with chat events:

  • Page URL: which pages drive the most chat interactions.
  • Traffic source: which channels (Google Ads, social, email) engage most with chat.
  • Device: desktop and mobile chat usage.

Use Explore -> Free form with eventName, pageLocation and sessionSourceMedium as dimensions.

Using events for other tags in GTM

With GTM, you can reuse the same triggers to fire other tags:

  • Meta Pixel: fire a Lead event when Send Message fires.
  • LinkedIn Insight Tag: create a custom conversion for chat engagement.
  • Remarketing: build audiences of visitors who opened the chat but didn't send a message.

Technical notes

  • The chat widget sends the events automatically. No code changes are needed on your site.
  • When the page loads gtag.js for a GA4 property, events are sent through window.gtag(). Otherwise they are pushed to window.dataLayer.
  • The octocom_chatted user property is set once per page load, on the visitor's first message.
  • With the web chat logLevel set to debug (see Configure the chat widget), the widget logs each event to the browser console, which helps when verifying the setup.

On this page