...
The first thing to do is initialize dataLayer variable. The piece of code that initializes the variable is:
Code Block language xml title Initialize dataLayer <script> dataLayer = []; </script>
This piece of code must be in all the pages that contain the search bar. There are two options:
- Add this code in the HTML head tag
Add this code just before the Google Tag Manager code:
Code Block language xml title Body option <body> <script> dataLayer = []; </script> <!-- Google Tag Manager --> ... <!-- End Google Tag Manager -->
The second thing to do is to add the event to dataLayer. This is and example.
Code Block language xml title Overlay Code <script> dataLayer.push({ 'eventTrackUrl': 'https://api-staging.empathybroker.com/tagging/v1/track/adoremeclientname/query?q=pushquery&catalog=default&scope=default&store=default&lang=en&totalHits=74&page=1', 'eventCallback': callback, 'event': 'sendTrackEvent' }); </script>
- Go to Google Tag Manager to continue with the integration process. No more code changes are needed.
- In Google Tag Manager you have to add triggers. To do it:
- Go to Triggers
- Click on New
- Name: sendTrackEvent
- Choose Event: Custom Event
- Fire On:
- Event name: sendTrackEvent
- Create Trigger
- Then, you have to create variables for received data in each event. The variables will always be the same, and they must have the dataLayer key names (In this case: eventQuery, eventStart, eventRows, eventOptions, eventCallback). For each of those variables repeat this process:
- Go to Variables
- At the bottom of the page, in the User-Defined Variables section, click New
- Name: One of the dataLayer key names (eventTrackUrl, eventCallback)
- Choose Type: Data Layer Variable
- Configure Variable:
- Data Layer Variable Name: Same name as the one in point c.
- Data Layer Version: Version 2
- Create Variable
- Finally, a Google Tag Manager tag must be created. To do it:
- Go to Tags
- Click on New
- Name: sendTrackEvent
- Choose Product: HTML
Configure Tag:
eventTrackUrl: {{trackUrl}} //Variable created on point 5
eventCallback: {{callback}} //Variable created on point 5
Code Block <script src="https://assets.empathybroker.com/apijs/1.3/empathy.resources.min.js" type="text/javascript"></script> <script> var empathyTAG = new EmpathyBrokerTAG(INSTANCE_ID, ENVIRONMENT).init(); empathyTAG.sendTrack({{trackUrl}}, {{callback}}); </script>
Fire On: More > Choose from existing Triggers: sendTrackEvent
Create Tag
...