# 3. Tags & Triggers in Google Tag Manager

## GTM Tags for Custom GA4 Events

**Name your tag according to the widget event you are setting up**

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FPXnZb95fUHcAZCgoURlO%2FXnip2023-04-24_15-02-54.jpg?alt=media&#x26;token=4e19d5aa-3c52-4b30-982b-b6b2a5cbadc1" alt=""><figcaption></figcaption></figure>

**Select the “Google Analytics GA4 Event” tag**

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FgHCkuHEEA33EEQobKgeS%2FXnip2023-04-24_15-00-53.jpg?alt=media&#x26;token=f68848e6-c9e8-4045-ad0c-bc97a7cc0acb" alt=""><figcaption></figcaption></figure>

**Configuration tag set to “GA4”**

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FhjaiFm3plnsKiI7oBmPG%2FXnip2023-04-24_15-03-37.jpg?alt=media&#x26;token=b5a52e5a-7300-4a1d-afe3-2a850e0e7616" alt=""><figcaption></figcaption></figure>

**Add "Event Name":** This should match your Event Name from above when you created the GA4 event (Example - widget\_opened)

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2F5uZMw2ZSsr4oMW65eJie%2FXnip2023-04-24_15-03-49.jpg?alt=media&#x26;token=4ac30ca5-a23c-41ad-8d90-cbfd73bf3956" alt=""><figcaption></figcaption></figure>

## **GTM Custom Event Triggers**

These custom event triggers will fire whenever ChatHQ sends event data into your GTM, which will then send the data from your GTM to your GA4.

**Follow the instructions and screenshots below to setup "Custom Event" triggers and apply them to your newly created tags:**

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FMRfANrS39ehVISgr4zHR%2FXnip2023-04-24_12-50-59.jpg?alt=media&#x26;token=0b91db47-01b4-4e36-a1db-0bac470c5589" alt=""><figcaption></figcaption></figure>

When creating a trigger for your GTM tag, select "Custom Event"

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FbVN4UuQYS4QJ5qeYXeDM%2FXnip2023-04-24_12-51-51.jpg?alt=media&#x26;token=6bf5b39c-0884-4b3f-a354-c6dd03014fcc" alt=""><figcaption></figcaption></figure>

You will need to configure your new trigger to match the Engagement Widget GA4 event your are connecting it to. For example, in the screenshot below you will see the "event name" perfectly matches the widget event associated with this trigger. You will repeate this process for every widget event you add to GA4 so that GTM knows to trigger the event when this data is passed into  the [Data Layer](#data-layer).

{% hint style="info" %}
Make sure you select the option **"All Custom Events"** when selecting when this trigger should fire!
{% endhint %}

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2Ff8rZValg9ah5JDK6qXsq%2FXnip2023-04-24_12-52-07.jpg?alt=media&#x26;token=fe8f982d-8ead-46ee-a563-13d39b1f5793" alt=""><figcaption></figcaption></figure>

When you have setup your Custom Event trigger properly, it should resemble the screenshot below.

{% hint style="warning" %}
**VERY IMPORTANT:** Remember, you will need a **NEW TRIGGER** for **EVERY** widget event you setup.
{% endhint %}

<figure><img src="https://2949826416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mh0SIdnTfBpdN11l3wk%2Fuploads%2FOc9KTTNLqUk5LX5QlsnR%2FXnip2023-04-24_12-51-13.jpg?alt=media&#x26;token=107de8e2-3e63-4af5-b751-495ac209cfad" alt=""><figcaption></figcaption></figure>

When you are finished creating all your custom event triggers, you should have a trigger for all the follow widget events:

* widget\_opened
* widget\_closed
* tool\_opened
* tool\_closed
* welcome\_message\_clicked
* welcome\_message\_closed
* all\_welcome\_messages\_closed


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chathq.io/api-and-developer-docs/custom-tracking-and-analytics/widget-events-in-google-analytics/3.-tags-and-triggers-in-google-tag-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
