Migrate to Messenger and enable journey tracking
This page explains the steps developers should take to migrate websites that use Predictive Engagement with web chats to journey tracking with Messenger.
For more information about migrating, see Migrate from web chat offers to web messaging offers and Web chat to web messaging migration and impact.
Configure Messenger and enable journey tracking
In the Genesys Cloud Admin menu, configure Messenger. For more information, see Configure Messenger in the Genesys Cloud Resource Center.
Important: On the Apps tab, turn the Predictive Engagement toggle On.
After you configure Messenger and enable journey tracking, initialization and tracking are handled automatically for you. Therefore, you need to remove any reference to the legacy ac('init')
method from your website as well as the actual snippet itself.
<script>
(function(a,t,c,l,o,u,d){a['_genesysJourneySdk']=o;a[o]=a[o]||function(){
(a[o].q=a[o].q||[]).push(arguments)},a[o].l=1*new Date();u=t.createElement(c),
d=t.getElementsByTagName(c)[0];u.async=1;u.src=l;u.charset='utf-8';d.parentNode.insertBefore(u,d)
})(window, document, 'script', 'https://apps.mypurecloud.com/journey/sdk/js/web/v1/ac.js', 'ac');
ac('init', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxx', { environment: 'use1' });
ac('pageview');
</script>
Messenger replaces the need for the web chat widget, so you need to remove the code related to it.
ac('dom', 'ready', function (){
console.log('The journey SDK is ready!');
});
Load the Genesys()
global function and verify that the Journey plugin is ready
To use Journey plugin commands and events to track website activity, you must first load the Genesys()
global function. For more information about how to do this, see globalFunction.
After you load the Genesys()
global function, subscribe to the Journey.ready
event and verify in your console log that the Journey plugin is working correctly:
Genesys('subscribe', 'Journey.ready', () => {
console.log('The journey plugin is ready!');
});
Remove all instances of the ac('ready')
method.
ac('dom', 'ready', () => {
console.log('The journey SDK is ready!');
});
Track page views
To track page views, use the Journey.pageview
command.
Genesys('command', 'Journey.pageview', {
//overrides can go here
});
Remove all instances of ac('pageview')
.
Record custom web events
To track custom web events, use the Journey.record
command. For information on how to define the custom web events that you can track with Journey.record
, see Journey.record
in the SDK commands and events page.
Genesys('command', 'Journey.record',{
eventName: 'product_added',
customAttributes: {
price: 15.99,
code: 'CDE-123',
name: 'Product',
hasBatteries: false
},
});
Remove all instances of ac('record')
.
ac('record', 'product_added',{
price:15.99,
code: 'CDE-123',
name: 'Product',
hasBatteries: false
});
Track URL changes
After you migrate to Messenger, Genesys Cloud automatically tracks URL changes.
Feature in progress: The ability to override the default onUrlChange
function is in development.
Remove all instances of autotrackUrlChange
.
ac('load', 'autotrackUrlChange',{
onUrlChange: (newUrl) => {
ac('pageview',{
location: newURL,
title: document.title
});
}
});
Subscribe to additional events
After you load the Genesys()
global function, you can subscribe to other events. For more information, see Subscribe to events. For a list of the events used with Messenger plugins, see Commands and events.
The following code example shows how to subscribe to qualified messaging offer events.
Genesys('subscribe', 'Journey.qualifiedWebMessagingOffer', (data) => {
console.log('event data:', data)
});
To complete your migration to web messaging, remove all subscriptions to legacy Events
methods, including on
, once
, and off
.
ac('on', 'webchat:offered', (data) => {
console.log('event data:', data);
});