Syncronex Knowledge BaseIntegrationPortal EventsCapturing Page Load Information in syncAccess

Capturing Page Load Information in syncAccess

syncAccess fires events when a user transitions from one ‘page’ to the next within the subscription workflow. Customers can write their own JavaScript code to listen for these events and then perform relevant tasks. For example, a customer might want to trigger some analytics service to record the user’s transition from one page to another.

Custom Event Handler File

Listening for these page transition events requires writing JavaScript functions that can be called by syncAccess when a particular page transition occurs.  These handlers must be gathered up in a single JavaScript file and made available via a public-facing URL to the Syncronex Support team.  Syncronex will take care of binding that file to your specific instance of syncAccess. 

Note, if you can’t support a public-facing JavaScript file (or don’t want to), you can also just provide the file to Syncronex so that it can be hosted for you.  The disadvantage to this approach is that every change you make to the handler file will require you to re-submit the changed file to Syncronex so that it can be re-posted.  If you use your own public file, then you can make changes to that file at your convenience without having to notify Syncronex.

Listening for the Page Transition Events

The syncAccess system will raise a Custom Event for each page transition.  You must write a function that can be associated with the custom event.  Doing this just requires that you provide your custom function as an argument to the addEventListener function.

window.document.addEventListener('Syncronex-SyncAccess', function(customEvent) {
       // custom code to take actions based on event...
});

The built-in addEventListener function takes two arguments: 1) the name of the event and 2) a function that will be called when that named event is triggered.

The event name will always be Syncronex-SyncAccess

Syncronex-SyncAccess Custom Event

The Syncronex-SyncAccess custom event returns different payloads depending on the context. In each case the object that is returned from the customEvent and passed to the handler that you create is a Custom Event. You can find more information on JavaScript Custom Events at https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events.

The ‘detail’ property of the custom event contains the Syncronex page transition event object. This ‘event’ property and the ‘data’ property within the ‘detail’ object contains the SyncAccess data that is reported on a page transition.

{
       event: [string],     // Name of specific syncronex event
       data: [object]       // event-specific payload data
}

Page Transition Event Object

event The specific page transition event that has been triggered. The event will provide a clue as to which page has been entered.
data Each event comes with an object that holds important contextual data about the event. The data property on the event is made up of one or more context objects: User Object, Navigation Object, Offer Object, and/or Voucher Lookup object

Event Property

The event property contains a string that describes the page transition event that has occurred. The following page transition events are currently supported:

  • syncaccess-login-page-entering
  • syncaccess-offers-page-entering
  • syncaccess-fed-auth-login-page-entering
  • syncaccess-register-page-entering
  • syncaccess-fed-auth-register-page-entering
  • syncaccess-purchase-page-entering
  • syncaccess-receipt-page-entering
  • syncaccess-continue-reading-page-entering
  • syncaccess-reset-password-request-page-entering
  • syncaccess-reset-password-page-entering
  • syncaccess-activation-page-entering
  • syncaccess-account-confirm-page-entering
  • syncaccess-voucher-redemption-page-entering
  • syncaccess-voucher-email-lookup-page-entering
  • syncaccess-voucher-receipt-page-entering
  • syncaccess-promo-code-page-entering
  • syncaccess-subscription-management-login-page-entering
  • syncaccess-subscription-management-main-page-entering
  • syncaccess-subscription-management-profile-page-entering
  • syncaccess-subscription-management-no-subscriptions-page-entering
  • syncaccess-subscription-management-error-page-entering
  • syncaccess-subscription-management-change-password-page-entering
  • syncaccess-subscription-management-ncs-content-page-entering

Important Note! Prior to version 5.2.11.5 of syncAccess, this prefix was incorrectly spelled “syncaccses” (e.g. syncacceses-login-page-entering).

Data Object

The data object contains the contextual data about the event. This object is made up of one or more context objects that contain a relevant portion of the event data.

{
       user: [object],
       navigation: [object],
       offer: [object],
       voucherLookup: [object]
}
User Object

The user context object contains information about the person navigating through the workflow. This might be a completely anonymous user (one who has never visited the site), a known user (someone that has already created an account within syncAccess), or a combination (i.e., a known user that has not yet logged into her account is treated as anonymous until logging in).

{
       anonymousUserId: [string],
       userId: [int],
       workflowId: [string]
}

User Context Object

anonymousUserId The non-logged-in identifier for the user. This is a persistent identifier for the user that is bound to the device (browser, etc.). The Anonymous user id will change if the user switches to a different device, deletes her cookies, or uses a private (aka Incognito) browser session.
userId The logged-in user identifier. This is an immutable, internal, identifier for the user within the system and never changes. The userId is only provided after the current user has logged in successfully. Until then, the userId value will show 0 (zero).
workflowId A unique identifier used to track the user’s current session through the system. This identifier resets after the user closes her browser.

The navigation object provides information about how the user arrived at the current workflow.  The properties within this object are relative to where the user was before she came into the Syncronex workflow.  For example, if the user arrived at the syncAccess Offers page after clicking a ‘subscribe’ button on the newspaper home page, then the referringUrl will contain the url of the newspaper’s home page.  This value will remain constant as the user moves throughout the workflow.  Page transitions within the workflow do not alter the currentUrl, referringUrl, returnUrl, or Origin values.

{
       currentUrl: [string],
       referringUrl: [string],
       returnUrl: [string],
       origin: [string]
}

Navigation Context Object

currentUrl The complete URL (including query string arguments) representing the page/view that the user is currently seeing
referringUrl The url from the page the user was on before coming into the Syncronex workflow. This will only show an external Url (when the user navigates between views in the portal, the referring Url is not changed. This value always represents the url the user was on before coming into the workflow)
returnUrl Holds the complete url to which a user will be returned upon completing the workflow. This can be blank (undefined) which just means that no, explicit, returnUrl was provided.  In those cases, the system will return the user to a default url that has been defined in the Admin tool
origin This holds the purchase tracking origin value. The origin can be used to record from where a user enters the purchase workflow.
Offer Object

The offer object provides information about the group of offers that were presented to the user. This “offer group” to which the list of offers was associated, and the list of offers, or plans, that the user was shown.

{
       offerGroup: [int],
       planList: [
       {
              Id: [int],
              PlanId: [int],
              Type: [string],
              TestName: [string],
              AZTestId: [int],
              DisplaySortOrder: [int],
              IsBestoffer: [bool]
       },...]
}

Offer Context Object

offerGroup
The internal identifier for the Offer Group container for the current list of plan offers.
planList
An array of plan offer objects that provide a bit more detail about what the user was presented.
Id
The internal identifier for the specific offer
PlanId
The internal identifier for the Plan that is being referenced in the offer. Typically, this value is the same as the Id value.
Type
Indicates whether or not the offer represents a static “Plan” or a “A-Z Test”.  AZ Tests are used to randomly present one of a selection of Plans as a means of testing the efficacy of different offers. A detailed explanation of AZ Tests is outside the scope of this document.
TestName
Despite the name, this property will show the Plan Name
AZTestId
An internal Identifier for the Test if this is an AZ Test-driven offer
DisplaySortOrder
Plans can be assigned a value used to determine how they should appear in a list when there are no other factors at play forcing the order. This is a deprecated property that might be deleted in a future version of the system.
IsBestOffer
A plan within an Offer Group can be tagged as a ‘best offer’ as a means of driving emphasis on a user interface. Only one plan from within an offer group can be tagged as a ‘best offer’.

Only pages that actually display a list of plan offers to a user or a purchase page will have an offer context object

Example Event Handler File

The following example code shows how to listen for the page transition events and then just write some information to the browser’s developer tool’s console. The example is deliberately simplistic in order to highlight the mechanics of connecting to the events. In a real-world event handler, more complex logic would be employed to, for instance, notify an analytics service of the user’s actions.

/*
 * Helper functions
 */
function getLogPrefix() {
    return '>>> sa-evt >>>';
}
function getLogNewLine() {
    return '\n' + getLogPrefix();
}
function logEventDataPart(eventDataPart) {
    console.log(getLogPrefix() + ' ' + eventDataPart);
}
function getEventNameForLog(eventName) {
    return 'event fired: ' + eventName;
}
function getUserDataPartForLog(userData) {
    var userId = userData.userId || 'anonymous';
    var anonId = userData.anonymousUserId;
    var workflowId = userData.workflowId;
    return 'UserId: ' + userId 
                      + '\tAnonymousId: ' + anonId 
                      + '\tworfklowId: ' + workflowId;
}
function getNavigationPartForLog(navigationData) {
    var referrer = navigationData.referringUrl || 'no referrer';
    var currentUrl = navigationData.currentUrl;
    var returnUrl = navigationData.returnUrl || 'no return url provided';
    var trackingOrigin = navigationData.origin || 'no origin provided';
    return 'current page url:\t' +
        currentUrl + getLogNewLine() +
        ' referring page:\t\t' +
        referrer + getLogNewLine() +
        ' return url:\t\t\t' +
        returnUrl + getLogNewLine() +
        ' tracking origin:\t\t' +
        trackingOrigin;
}
function getOffersPartForLog(offerData) {
    var offerGroupId = offerData.offerGroup;
    var plans = offerData.planList;
    var logPart = '';
    var planPart = '';
    if(offerGroupId){
        logPart = 'user saw offer group ' + offerGroupId.toString();
        planPart = getLogNewLine() + ' which contained the following offers:';
        for (var i = 0; i < plans.length; i++) {
            planPart += getLogNewLine() + '\t\t' 
                 + plans[i].TestName + ' (' 
                 + plans[i].Type + '-'
                 + plans[i].planId + ')';
        }
    }
    return logPart + planPart;
}
/*
 * Output event details to console
 */
function logEvent(customEvent) {
    var eventName = customEvent.detail.event;
    var eventData = customEvent.detail.data;
    
    var navigationData = eventData.navigation;
    var userData = eventData.user;
    var offerData = eventData.offer || null;
    logEventDataPart('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
    logEventDataPart(getEventNameForLog(eventName));
    logEventDataPart(getUserDataPartForLog(userData));
    logEventDataPart(getNavigationPartForLog(navigationData));
    if (offerData) {
        logEventDataPart(getOffersPartForLog(offerData));
    }
    logEventDataPart('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
}
/*
 * Main wire-up of the Page Transition Events
 */
window.document.addEventListener('Syncronex-SyncAccess', function(customEvent) {
    logEvent(customEvent);
});

When this code is added to your custom event handling file (and once Syncronex has associated your file to your application instance), the developers console would display something like this when the user visits the offers page:

>>> sa-evt >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>> sa-evt >>> event fired: syncacceses-login-page-entering
>>> sa-evt >>> UserId: anonymous  AnonymousId: 3372c198-5f97-4dd3-924a-21d7d6ee3817      worfklowId: g859uMTmJE2azamMBpjORg
>>> sa-evt >>> current page url:  https://syncaccess-acme-testpage.dev.syncronex.com/portal/#/offers/?origin=offers
>>> sa-evt >>> referring page:           no referrer
>>> sa-evt >>> return url:               no return url provided
>>> sa-evt >>> tracking origin:          offers
>>> sa-evt >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>> sa-evt >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>> sa-evt >>> event fired: syncacceses-offers-page-entering
>>> sa-evt >>> UserId: anonymous  AnonymousId: 3372c198-5f97-4dd3-924a-21d7d6ee3817      worfklowId: g859uMTmJE2azamMBpjORg
>>> sa-evt >>> current page url:  https://syncaccess-acme-testpage.dev.syncronex.com/portal/#/offers/?origin=offers
>>> sa-evt >>> referring page:           no referrer
>>> sa-evt >>> return url:               no return url provided
>>> sa-evt >>> tracking origin:          offers
>>> sa-evt >>> user saw offer group 9
>>> sa-evt >>> which contained the following offers:
>>> sa-evt >>>             Qualified Plan (Plan-5)
>>> sa-evt >>>             SA-Only Plan (Plan-14)
>>> sa-evt >>>             Circ Pro Print (Plan-13)
>>> sa-evt >>>             Monthly Digital (Plan-3)
>>> sa-evt >>>             24-Hour Pass (Plan-9)
>>> sa-evt >>>             DM Plan (Plan-7)
>>> sa-evt >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Data Objects Associated with Each Event

The data that is provided for each page transition event differs, depending on the context of the particular event.

{
       event: [string],     // Name of specific syncronex event
       data: {
              user: [object],
              navigation: [object],
              offer: [object],
              voucherLookup: [object]
       }
}

Here’s a list of the data objects that are provided with each event:

syncaccess-login-page-entering

  • user
  • navigation

syncaccess-offers-page-entering

  • user
  • navigation
  • offer
syncaccess-fed-auth-login-page-entering
  • user
  • navigation
syncaccess-register-page-entering
  • user
  • navigation
syncaccess-fed-auth-register-page-entering
  • user
  • navigation
syncaccess-purchase-page-entering
  • user
  • navigation
syncaccess-receipt-page-entering
  • user
  • navigation
syncaccess-continue-reading-page-entering
  • user
  • navigation
syncaccess-reset-password-request-page-entering
  • user
  • navigation
syncaccess-reset-password-page-entering
  • user
  • navigation
syncaccess-activation-page-entering
  • user
  • navigation
syncaccess-account-confirm-page-entering
  • user
  • navigation
syncaccess-voucher-redemption-page-entering
  • user
  • navigation
syncaccess-voucher-email-lookup-page-entering
  • user
  • navigation
syncaccess-voucher-receipt-page-entering
  • user
  • navigation
syncaccess-promo-code-page-entering
  • user
  • navigation
syncaccess-subscription-management-login-page-entering
  • user
  • navigation
syncaccess-subscription-management-main-page-entering
  • user
  • navigation
syncaccess-subscription-management-profile-page-entering
  • user
  • navigation
syncaccess-subscription-management-no-subscriptions-page-entering
  • user
  • navigation
syncaccess-subscription-management-error-page-entering
  • user
  • navigation
syncaccess-subscription-management-change-password-page-entering
  • user
  • navigation
syncaccess-subscription-management-ncs-content-page-entering
  • user
  • navigation

Browser Support

The Syncronex-SyncAccess custom event has been tested against Google Chrome, Firefox, Microsoft Edge, and Microsoft Internet Explorer versions 11, 10, and 9.

Important Note! Microsoft Internet Explorer is not supported in versions before 5.2.11.5 of syncAccess.