Difference between revisions of "ATC/Current/SDK/autotrackURLChange"
m (Text replacement - "\|Platform=([^\|]*)GenesysEngage-onpremises([\|]*)" to "|Platform=$1GenesysEngage-cloud$2") |
(Published) |
||
Line 3: | Line 3: | ||
|DisplayName=autotrackURLChange | |DisplayName=autotrackURLChange | ||
|TocName=autotrackURLChange | |TocName=autotrackURLChange | ||
− | |Context=Learn how to customize tracking for Single Page Application (SPA) | + | |Context=Learn how to customize tracking for Single Page Application (SPA) web sites. Alternatively, use your preferred tag manager to customize and deploy the SPA tracking snippet. For more information, see {{Link-AnywhereElse|product=ATC|version=Current|manual=Event|topic=About_event_tracking}}. If you are just getting started, read {{Link-SomewhereInThisVersion|manual=AdminGuide|topic=Tracking_snippet}}. |
|Dimension=Modules | |Dimension=Modules | ||
|ComingSoon=No | |ComingSoon=No | ||
− | |Platform=GenesysEngage-cloud | + | |Platform=PureConnect, GenesysCloud, GenesysEngage-cloud |
− | |||
|Section={{Section | |Section={{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 17: | ||
*{{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 22: | ||
|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 39: | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}oldUrl | {{!}}{{!}}oldUrl | ||
− | {{!}}{{!}} | + | {{!}}{{!}}Previous URL before the change. |
{{!}}{{!}}string | {{!}}{{!}}string | ||
{{!}}{{!}}required | {{!}}{{!}}required | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}newUrl | {{!}}{{!}}newUrl | ||
− | {{!}}{{!}} | + | {{!}}{{!}}Possibly changed URL. |
{{!}}{{!}}string | {{!}}{{!}}string | ||
{{!}}{{!}}required | {{!}}{{!}}required | ||
Line 57: | Line 50: | ||
===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 72: | Line 65: | ||
}, function() { }); | }, function() { }); | ||
</source> | </source> | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 79: | Line 70: | ||
|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 87: | ||
{{!}}- | {{!}}- | ||
{{!}}{{!}}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 97: | ||
|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 120: | ||
}, function() { }); | }, function() { }); | ||
</source> | </source> | ||
− | |||
− | |||
|Status=No | |Status=No | ||
}}{{Section | }}{{Section | ||
Line 142: | Line 125: | ||
|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 | ||
}} | }} | ||
}} | }} |
Revision as of 18:07, December 16, 2020
Contents
Learn how to customize tracking for Single Page Application (SPA) web sites. 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 (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 });