> For the complete documentation index, see [llms.txt](https://help.littledata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.littledata.io/partner-recipes/gorgias/tracking-gorgias-google-analytics.md).

# Track Gorgias live chat events in GA4

Add a short script to your Shopify theme to send Gorgias live chat events to GA4, so you can see how chat affects purchasing.

[Gorgias](https://www.gorgias.com) is a help desk and customer service tool for ecommerce brands. If your store uses the Gorgias chat widget, you can send chat events to Google Analytics 4 (GA4). Then you can see how conversations with your support team before checkout affect purchasing.

### What you can learn

With chat events in GA4, you can:

* Compare ecommerce conversion rate by how often shoppers use chat.
* Split chat usage by marketing channel or product, and see trends over time.
* Look at widget open rate by screen size or browser, to spot usability issues.

{% hint style="success" %}
These events sit alongside Littledata's [Shopify tracking in GA4](https://help.littledata.io/integrations/shopify-to-google-analytics), so you can link chat interactions with add-to-carts and purchases.
{% endhint %}

### Events tracked

The Gorgias chat widget lets you [listen to chat events](https://docs.gorgias.com/en-US/advanced-customization-new-chat-81792). The script on this page sends these events to GA4:

| GA4 event name             | When it fires                 |
| -------------------------- | ----------------------------- |
| `gorgias_widget_opened`    | The chat widget is opened     |
| `gorgias_widget_closed`    | The chat widget is closed     |
| `gorgias_message_sent`     | A customer sends a message    |
| `gorgias_message_received` | A customer receives a message |

### Add the script

The script waits for the Gorgias widget to load, listens for chat events and sends each one to GA4 using `gtag`. It uses the `gtag` function that Littledata's tracking script sets up on your storefront. If the Google tag library hasn't finished loading, `gtag` queues the events and sends them once it's ready.

{% stepper %}
{% step %}
**Open your theme code**

In your Shopify admin, go to **Online Store** > **Themes**. Next to your current theme, click **...** > **Edit code**.
{% endstep %}

{% step %}
**Paste the script into theme.liquid**

Open `layout/theme.liquid` and paste this script just before the closing `</body>` tag:

```html
<script>
  (function () {
    var eventsToTrack = [
      { gorgias: "message:sent", ga: "gorgias_message_sent" },
      { gorgias: "message:received", ga: "gorgias_message_received" },
      { gorgias: "widget:opened", ga: "gorgias_widget_opened" },
      { gorgias: "widget:closed", ga: "gorgias_widget_closed" },
    ];

    var initGorgiasChatPromise = window.GorgiasChat
      ? window.GorgiasChat.init()
      : new Promise(function (resolve) {
          window.addEventListener("gorgias-widget-loaded", function () {
            resolve();
          });
        });

    initGorgiasChatPromise.then(function () {
      eventsToTrack.forEach(function (event) {
        window.GorgiasChat.on(event.gorgias, function () {
          if (typeof window.gtag === "function") {
            window.gtag("event", event.ga);
          }
        });
      });
    });
  })();
</script>
```

To track other Gorgias events, add a row to `eventsToTrack` with the Gorgias event name and the GA4 event name you want.
{% endstep %}

{% step %}
**Save and test**

Click **Save**. Open your store, open the chat widget and send a test message. You should see the events in a browser debugger for GA4, or in GA4 **Realtime** reports.

<div data-with-frame="true"><figure><img src="https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-6105fcc751eb96e6e6efa10645ecbb7d1719b262%2Fscreenshot-2024-01-22-at-13.20.29.png?alt=media" alt="Gorgias chat on a Shopify store next to a GA4 debugger showing gorgias_ events"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### Use the events in GA4

Within 24 hours, the events show up under **Reports** > **Engagement** > **Events**.

<div data-with-frame="true"><figure><img src="https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-2c60f4420d6ccd7bc09a3059c053d4f020a638c1%2Fscreenshot-2024-01-22-at-13.29.40.png?alt=media" alt="GA4 Events report showing event count by event name over time"><figcaption></figcaption></figure></div>

To see how many people who received a message went on to buy, build a [segment](https://help.littledata.io/google-analytics/behavior/segments-in-google-analytics-4) of users with a `gorgias_message_received` event and compare it with users who didn't have one. You can also check whether more messages lead to more purchases.

### Related articles

* [Gorgias](https://help.littledata.io/partner-recipes/gorgias)
* [Segments in GA4](https://help.littledata.io/google-analytics/behavior/segments-in-google-analytics-4)
* [Shopify to GA4 connection](https://help.littledata.io/integrations/shopify-to-google-analytics)
