# Tracking with Google Tag Manager

In this documentation we show an example of how to connect the search events to an analytics account via GTM.

After this configuration you can follow the steps in the [Google Site Tag Events Tracking](https://documentation.ajaxsearchpro.com/events-tracking#events-tracking) documentation to configure the events.

### Configuring Variables

There are 4 Data Layer variables, which has to be added:

* event\_category
* event\_label
* event\_name
* event\_value

To add the variables, open up your Google Tag Manager account, click on **Workspace** and **Variables** menu. Under the **User-Defined Variables** table click the **New** button.

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FSDRQcB5CMOfrZuhxxObc%2Fimage.png?alt=media\&token=73aed8fa-22b9-4eef-abc3-2188d055fdaa)

Choose **Data Layer Variable** for the type and enter the name of the variable and then **Save**. Do this for all 4 variables (event\_category, event\_label, event\_name, event\_value)

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2F90qsv4rAlKJK9vsjOg0Q%2Fimage.png?alt=media\&token=251a4cfb-6859-4c85-b7c7-13cecad51011)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2F70UC7FvwSlVwcPMeMfez%2Fimage.png?alt=media\&token=e0ce9f96-f019-4c90-ad76-c84c4854963c)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FShSdBl3c3frm9Ua2w9k5%2Fimage.png?alt=media\&token=a9485f34-af2e-4db2-8b6c-66528f74339c)

After the creation, you should be able to see these variables in the list. Now, we can use these variables in the **Tags**.

### Triggers setup

After the variables have been added, a trigger must be configured. The trigger will help recognize the events originating from Ajax Search Pro.

To setup a trigger hit the **Triggers** menu, and click the **New** button. Name the trigger "Ajax Search Pro Events" and choose **Custom Event** as the event type. Enter **asp\_event** as the Event name and hit **Save**.

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FJSJ8s6Zm7NEJjfAXDZWS%2Fimage.png?alt=media\&token=517dc77f-155f-456c-83e6-b7d478c2b145)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FnO3m34XuXtchGAXg8csX%2Fimage.png?alt=media\&token=55e9022a-4104-4e73-9324-8eaaaf84fcf1)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FJ7rQ90eQlsO119DyAlyK%2Fimage.png?alt=media\&token=5531b01f-b015-4ff0-b5fd-98ea78d6540d)

Now, we can use the **asp\_event** from the Data Layer to connect to a Tag.

### Tags setup

In this example, we will convert the **asp\_event** to a Google Analytics 4 Event to a with a specific tracking ID.

Go to the **Tags** menu and click the **New** button. Name the tag as you like, we are using "Ajax Search Pro GA4 Event" in the example. Click the **Tag Configuration area** and choose **Google Analytics: GA4 Event**.

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2F4IwPkCCveDHSlS1zzIba%2Fimage.png?alt=media\&token=f7c36ace-f438-4749-aa7e-ba8b39f1fed0)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FsdiXagVNXT3n1yXSs3go%2Fimage.png?alt=media\&token=8b1b6605-5a02-40eb-8bdc-c6c27866b0b7)

Choose to set the **Configuration Tag** manually, by choosing "None - Manually Set ID", and enter your google analytics **Measurement ID.**

For the **Event name** choose the **Event** variable or enter `{{event_name}}`

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FRsnVwDBLRL40OhrAdx6k%2Fimage.png?alt=media\&token=553d8217-c137-4bd7-a558-0fa0120c7d35)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FZBvTra0Vo1Vl9c85Fbo1%2Fimage.png?alt=media\&token=6ee0c668-46d2-4281-b086-e18fe2bd7bec)

Almost done, now all we need are the Event Parameters, where we add the variables, which were created in the first step.

To the Event Parameters section add the following rows:

| Parameter Name  | Value               |
| --------------- | ------------------- |
| event\_category | {{event\_category}} |
| event\_label    | {{event\_label}}    |
| event\_value    | {{event\_value}}    |

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FXFhdcyAqTuX94gWYkJE2%2Fimage.png?alt=media\&token=bf23d995-195a-4e6c-a64f-93a049bd4093)

Once this is done, scroll down to **Triggering** and Add **Ajax Search Pro Events** as the trigger and **Save**.

![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2F5jZzlwpYTt7YZx4wLG4L%2Fimage.png?alt=media\&token=7ad878ca-8f83-48d9-9970-52da33ef6f1e)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2FIlTNDsuK0U4kd7FgPohX%2Fimage.png?alt=media\&token=d5a506b8-8f0e-4b99-a15b-c6d792f29b35)![](https://1706764988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-L9jkFgNo4lpUof35gvS%2Fuploads%2F4ejxAZI1JHJuhW1FXYC2%2Fimage.png?alt=media\&token=f634732e-3eb8-420f-ad54-50d8e85b55fb)

### Measurement

After this setup all the data is now sent to the defined google Analytics 4 account. After the installation see the [Events Tracking](https://documentation.ajaxsearchpro.com/analytics-integration/..#events-tracking) to setup the desired events to track.
