Difference between revisions of "ATC/Current/SDK/autotrackURLChange"
m (Text replacement - "\|Platforms?=([^\|]*)PureCloud([\|]*)" to "|Platform=$1GenesysCloud$2") |
m (Text replacement - "Genesys Cloud" to "Genesys Cloud CX") |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
|Dimension=Modules | |Dimension=Modules | ||
|ComingSoon=No | |ComingSoon=No | ||
− | |Platform= | + | |Platform=PureConnect, GenesysCloud, GenesysEngage-cloud |
− | |||
|Section={{Section | |Section={{Section | ||
+ | |alignment=Vertical | ||
+ | |structuredtext={{NoteFormat|1=This article only applies to customers using {{Link-AnywhereElse|product=ATC|version=Current|manual=AdminGuide|topic=About_web_chats|display text=web chat}}. If you are a Genesys Cloud CX customer, we encourage you to use the new {{Link-AnywhereElse|product=ATC|version=Current|manual=AdminGuide|topic=About_web_messaging|display text=web messaging}} feature to replace web chat.|2=}}<br /> | ||
+ | |Status=No | ||
+ | }}{{Section | ||
|sectionHeading=Description | |sectionHeading=Description | ||
|anchor=autoTrackURLChangeDesc | |anchor=autoTrackURLChangeDesc | ||
|alignment=Vertical | |alignment=Vertical | ||
− | + | |structuredtext=The <code>autotrackURLChange</code> module tracks activity on an SPA webpage when a user clicks through relative links or when software-driven activity changes the URL or browser history. {{NoteFormat|The <code>autotrackURLChange</code> module is automatically loaded when you load the SPA snippet.|}}To customize how <code>autotrackURLChange</code> tracks user activity, use the following options: | |
− | |||
− | |structuredtext=The <code>autotrackURLChange</code> module tracks activity on an SPA webpage when a user clicks through relative links or when software-driven activity changes the URL or browser history. {{NoteFormat|The <code>autotrackURLChange</code> module is automatically loaded when you load the SPA snippet.|}}To customize how <code>autotrackURLChange</code> tracks user activity, use | ||
*{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange#isURLChange|display text=isUrlChange}} | *{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange#isURLChange|display text=isUrlChange}} | ||
Line 20: | Line 21: | ||
*{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange#callback|display text=callback}} | *{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange#callback|display text=callback}} | ||
*{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange|anchor=delay|display text=delay}} | *{{Link-SomewhereInThisVersion|manual=SDK|topic=autotrackURLChange|anchor=delay|display text=delay}} | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 27: | Line 26: | ||
|anchor=isURLChange | |anchor=isURLChange | ||
|alignment=Vertical | |alignment=Vertical | ||
− | + | |structuredtext='''Description:''' Checks whether the URL changed since the last check. | |
− | |||
− | |structuredtext=Description: | ||
− | Type: | + | '''Type:''' Function |
− | Status: | + | '''Status:''' Default implementation available; can be overwritten |
− | Returns: Boolean | + | '''Returns:''' Boolean |
− | Arguments: | + | '''Arguments:''' See the following table. |
{{{!}} class="wikitable" | {{{!}} class="wikitable" | ||
{{!}}- | {{!}}- | ||
Line 46: | Line 43: | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}oldUrl | {{!}}{{!}}oldUrl | ||
− | {{!}}{{!}} | + | {{!}}{{!}}Previous URL before the change. |
{{!}}{{!}}string | {{!}}{{!}}string | ||
{{!}}{{!}}required | {{!}}{{!}}required | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}newUrl | {{!}}{{!}}newUrl | ||
− | {{!}}{{!}} | + | {{!}}{{!}}Possibly changed URL. |
{{!}}{{!}}string | {{!}}{{!}}string | ||
{{!}}{{!}}required | {{!}}{{!}}required | ||
Line 57: | Line 54: | ||
===Example=== | ===Example=== | ||
− | This example shows how to exclude tracking when a | + | This example shows how to exclude tracking when a visitor clicks relative links on a webpage. |
<source lang="Javascript"> | <source lang="Javascript"> | ||
Line 63: | Line 60: | ||
isUrlChange: function(oldUrl, newUrl) { | isUrlChange: function(oldUrl, newUrl) { | ||
if (oldUrl !== newUrl) { | if (oldUrl !== newUrl) { | ||
− | if (newUrl.includes(oldUrl)) { | + | if (oldUrl !== '' && newUrl.includes(oldUrl)) { |
return false; | return false; | ||
} | } | ||
Line 72: | Line 69: | ||
}, function() { }); | }, function() { }); | ||
</source> | </source> | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 79: | Line 74: | ||
|anchor=onUrlChange | |anchor=onUrlChange | ||
|alignment=Vertical | |alignment=Vertical | ||
− | + | |structuredtext='''Description:''' Runs when the URL changes through a relative link or SPA routing functionality. | |
− | |||
− | |structuredtext=Description: | ||
− | Type: | + | '''Type:''' Function |
− | Status: | + | '''Status:''' Default implementation available; tracks pageviews through <code>ac('pageview')</code>; can be overwritten |
− | Returns: | + | '''Returns:''' Void |
− | Arguments: | + | '''Arguments:''' See the following table. |
{{{!}} class="wikitable" | {{{!}} class="wikitable" | ||
{{!}}- | {{!}}- | ||
Line 98: | Line 91: | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}newURL | {{!}}{{!}}newURL | ||
− | {{!}}{{!}} | + | {{!}}{{!}}URL that the visitor changed to. |
{{!}}{{!}}string | {{!}}{{!}}string | ||
{{!}}{{!}}required | {{!}}{{!}}required | ||
{{!}}} | {{!}}} | ||
− | {{NoteFormat|By default, the tracking snippet tracks page views via <code>ac('pageview')</code>. If you override the default behavior using <code>onUriChange</code>, remember to | + | {{NoteFormat|By default, the tracking snippet tracks page views via <code>ac('pageview')</code>. If you override the default behavior using <code>onUriChange</code>, remember to include this call in the new function manually.|}} |
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 110: | Line 101: | ||
|anchor=callback | |anchor=callback | ||
|alignment=Vertical | |alignment=Vertical | ||
− | + | |structuredtext=When a module loads, callback is executed. No arguments pass to the callback. | |
− | |||
− | |structuredtext=When a module | ||
===Example=== | ===Example=== | ||
− | Your SPA page may use routers or relative links to change the page URL without changing the page title. In this case, the default <code>ac('pageview')</code> call tracks all page views as occurring on the same page. Visit journey information that appears in Live Now and the agent UI does not reflect actual | + | Your SPA page may use routers or relative links to change the page URL without changing the page title. In this case, the default <code>ac('pageview')</code> call tracks all page views as occurring on the same page. Visit journey information that appears in Live Now and the agent UI does not reflect actual visitor behavior. To change this behavior, customize the onUrlChange option as shown in the following example. |
<source lang="Javascript"> | <source lang="Javascript"> | ||
Line 135: | Line 124: | ||
}, function() { }); | }, function() { }); | ||
</source> | </source> | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 142: | Line 129: | ||
|anchor=delay | |anchor=delay | ||
|alignment=Vertical | |alignment=Vertical | ||
− | |||
− | |||
|structuredtext=Use this option to set a delay between the time when the SDK realizes there is a URL change and when it sends the <code>onUrlChange</code> function. | |structuredtext=Use this option to set a delay between the time when the SDK realizes there is a URL change and when it sends the <code>onUrlChange</code> function. | ||
===Example=== | ===Example=== | ||
− | This example sets a 1-second delay | + | This example sets a 1-second delay to give the application time to change the page title to match the current URL. |
ac('load', 'autotrackUrlChange', { delay: 1000 }); | ac('load', 'autotrackUrlChange', { delay: 1000 }); | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}} | }} | ||
}} | }} |
Latest revision as of 21:28, November 9, 2021
Contents
Learn how to customize tracking for Single Page Application (SPA) websites. Alternatively, use your preferred tag manager to customize and deploy the SPA tracking snippet. For more information, see About event tracking with tag managers. If you are just getting started, read Predictive Engagement tracking snippet.
Description
autotrackURLChange
module tracks activity on an SPA webpage when a user clicks through relative links or when software-driven activity changes the URL or browser history. autotrackURLChange
module is automatically loaded when you load the SPA snippet.autotrackURLChange
tracks user activity, use the following options:
isUrlChange
Description: Checks whether the URL changed since the last check.
Type: Function
Status: Default implementation available; can be overwritten
Returns: Boolean
Arguments: See the following table.
Name | Description | Type | Status |
oldUrl | Previous URL before the change. | string | required |
newUrl | Possibly changed URL. | string | required |
Example
This example shows how to exclude tracking when a visitor clicks relative links on a webpage.
ac('load', 'autotrackUrlChange', {
isUrlChange: function(oldUrl, newUrl) {
if (oldUrl !== newUrl) {
if (oldUrl !== '' && newUrl.includes(oldUrl)) {
return false;
}
return true;
}
return false;
}
}, function() { });
onUrlChange
Description: Runs when the URL changes through a relative link or SPA routing functionality.
Type: Function
Status: Default implementation available; tracks pageviews through ac('pageview')
; can be overwritten
Returns: Void
Arguments: See the following table.
Name | Description | Type | Status |
newURL | URL that the visitor changed to. | string | required |
ac('pageview')
. If you override the default behavior using onUriChange
, remember to include this call in the new function manually.callback
When a module loads, callback is executed. No arguments pass to the callback.
Example
Your SPA page may use routers or relative links to change the page URL without changing the page title. In this case, the default ac('pageview')
call tracks all page views as occurring on the same page. Visit journey information that appears in Live Now and the agent UI does not reflect actual visitor behavior. To change this behavior, customize the onUrlChange option as shown in the following example.
ac('load', 'autotrackUrlChange', {
onUrlChange: function(newUrl) {
let customTitle = document.title;
if (newUrl.includes('marketing')) {
customTitle = customTitle + 'marketing';
}
if (newUrl.includes('contact-us')) {
customTitle = customTitle + 'contact-us';
}
// supply pageOverrides with location and custom title field
ac('pageview', {
location: window.location.href,
title: customTitle
});
}
}, function() { });
delay
Use this option to set a delay between the time when the SDK realizes there is a URL change and when it sends the onUrlChange
function.
Example
This example sets a 1-second delay to give the application time to change the page title to match the current URL.
ac('load', 'autotrackUrlChange', { delay: 1000 });