How to Integrate Tracking
LoyJoy itself does not track customer website behavior. Instead, it supports integration with tracking solutions such as Google Analytics, Google Tag Manager or a custom solution provided by you.
In the Publish
tab of your chat experience you can select, if you want to integrate the experience with Google Analytics, Google Tag Manager or want to call a custom script, when events are emitted.
How to Connect LoyJoy to Google Global Site Tag / Google Analytics (gtag.js)
When you select Google Analytics
, the following script will automatically be executed on each LoyJoy event:
gtag && gtag('event', type, {
'event_category': 'LoyJoy Chat',
'event_action': detail && detail.process_name,
'event_label': type + (detail.label ? '/' + detail.label : '')
})
How to Connect LoyJoy to Google Tag Manager (gtm.js)
When you select Google Tag Manager
, the following script will automatically be executed on each LoyJoy event:
dataLayer && dataLayer.push && dataLayer.push({
'event': type,
'event_category': 'LoyJoy Chat',
'event_action': detail && detail.process_name,
'event_label': type + (detail.label ? '/' + detail.label : '')
})
With the default Google Tag Manager integration, the saved events will have the following fields:
Field | Contents |
---|---|
event | Event name / type. E.g. session_started . See here |
event_category | Fixed, always LoyJoy Chat |
event_action | Name of the experience |
event_label | Event name + optional label, e.g. quick reply title |
Custom JavaScript Code
When you select Custom
, you can enter custom JavaScript code, which should be executed on each LoyJoy event, e.g.:
if ([
'data_collection_question_answered', 'interaction', 'link_clicked', 'load', 'open', 'session_interacted', 'session_started', 'start'
].includes(event.type)) {
dataLayer && dataLayer.push && dataLayer.push({
'event': 'LoyJoy ChatBot ' + event.type,
'event_category': 'LoyJoy ChatBot',
'event_action': ['load', 'session_interacted', 'session_started'].includes(event.type) ? event.type : event.detail && (event.detail.process_name || event.detail.process_id),
'event_label': ['load', 'session_interacted', 'session_started'].includes(event.type) ? event.type : event.type + (event.detail && event.detail.label ? ' / ' + event.detail.label : '') + (event.detail && (event.detail.sub_process_name || event.detail.sub_process_id) ? ' / ' + (event.detail.sub_process_name || event.detail.sub_process_id) : '')
})
}
Facebook Pixel
A Facebook / Meta pixel integration could look like this:
if (event.type === 'link_clicked') {
fbq('track', 'Lead', { process: event.detail.process_name });
}
Typically, you might want to adjust the event type being checked for (here link_clicked
) as well as the tracked event you send to Facebook (here Lead
).