Support
> Advanced Topics > How to track Search and Click events in Google Tag ManagerHow to track Search and Click events in Google Tag Manager
Introduction
A common scenario is that you may want to track Store Locator Search events as part of your Google Adwords or other Conversion and goal tracking process using Google Tag Manager. For example, whenever a visitor searches for a location inside your store locator you could record this as a goal inside Google Adwords.
Each time a Search is conducted inside your store locator, the following function is called by the locator if it exists:
storeLocatorSearchEventHandler(eventData)
A search event is recorded in each of the following scenarios:
- The 'My Location' button is pressed by the visitor.
- The visitor is automatically geolocated (if the Customer Geolocation setting is set to 'Automatically locate user' on your Settings page).
- The visitor searches for an address in the address search field
- The visitor searches for a location using the location search field (if this is enabled).
Getting your Goal Conversion Codes from Google Adwords
Before you get started, you'll need to get the conversion codes for the conversion action which you want to track. Here's the process:
1. In Adwords select Tools -> Conversions
2. Click on the Conversion Action you would like to link
3. Under Tag Setup scroll down select 'Use Google Tag Manager'
4. Your Conversion ID and Conversion Label are shown there (see example below):
Google Tag Manager Installation
1. First, create a new tag.
2. Choose 'Custom HTML' as the type.
3. Paste the following into the HTML field with the Conversion ID and Conversion Label values taken from your Google Adwords Conversion tracking console:
function storeLocatorSearchEventHandler(eventData) {
gtag('event', 'Store Locator', {
'event_category': 'Search',
'event_label': 'Store Locator Search Event: ' + eventData.type,
'send_to': 'AW-CONVERSION_ID/AW-CONVERSION_LABEL'
});
}