Available Javascript Methods
MXO provides the following Javascript methods:
Name | Description |
---|---|
sendInteraction | Trigger an Interaction Point call and pass data to MXO. Receive mainly optimization instructions. processResponse handles the 'response' object returned by the sendInteraction method. |
processResponse | Handles the 'response' object returned by the sendInteraction method. |
sendProperties | Send data about the current customer or context to MXO. Typically, this would include additional, dynamic, data about the current Interaction Point. |
sendResponseCode | Register a response code for any returned Actions. |
getTid | Return the TID for current browser. |
generatePixelUrl | Return the MXO Pixel URL for the current customer and Space. This is used mainly for cookie-sync operations between MXO and a third-party vendors' tag or SDK. |
Promises
Many of the customerApi methods make asynchronous calls to MXO. Therefore the value returned by these methods is not the actual response from MXO, but a promise object, that can be used to register callbacks when the response is returned from MXO.
The promise object used by the available MXO methods is compatible with the jQuery promise API implementing the usual then(), done, fail(), and always() methods.
sendInteraction
customerApi.sendInteraction(interactionPath, properties);
The sendInteraction() method sets the context for the customer, by making a call to an Interaction Point in MXO and returning content for any Optimization Points associated with that Interaction.
Any properties passed on this call are made available in MXO. You can configure Attribute Capture Points to capture those properties, if you want to persist that data for the current customer.
Any subsequent calls to sendProperties() or sendResponseCode() are within the Interaction Point context established with the original call to the sendInteraction() method.
Use Case
You need to trigger a specific event for a dynamic web page. For example, if a single page is presented to both authenticated and unauthenticated customers, and you want to trigger an Interaction to capture the login event only for authenticated customers.
Required Input
Parameter | Description |
---|---|
interactionPath |
Required. The path of the Interaction Point to send to MXO. This will be appended to the current Touchpoint. You can either send the path for the current context or a fully qualified URI, including the base Touchpoint.For example /authenticated might be used as the path to trigger an authenticated login event.You can specify the full URI, including Touchpoint, on a per request basis by providing a fully qualified URI as the Interaction path.For example, a customer logs in to your hotel wifi portal, and you want to track that they are actually in the hotel. You can trigger an Interaction Point on your physical Touchpoint by including the full Touchpoint URI:
|
properties |
Optional. A JavaScript object containing your properties, in the format:
|
Returns
A promise into which a data object is passed, when the REST call completes, that contains the following:
{ optimizations: [{ data: '', dataMimeType: '', directives: '', path: '', responseId: '' }], tid: '' }
processResponse
customerApi.processResponse(response[,retryFlag=true, timeoutMS=1050]);
The processResponse() method returns the required response after you call the sendInteraction() method. This returns a promise containing details about on-click Capture Points and Optimization Points in an object.
Use cases
You need to delay the triggering of an optimization for a period of time. For example:
-
If you need to trigger an optimization a few seconds after a page loads rather then immediately, you would send an interaction with a zero second timeout.
-
If you need to trigger an optimization on a page that is in another region, you would increase the timeout for that optimization.
Required Input
Parameter | Description |
---|---|
response |
Required. The fulfilled response passed from a sendInteraction() promise and accessed with a then() method.This is needed to bind and track events on a web page alongside optimizations. Returned upon a successful promise.
|
retryFlag |
Optional. A boolean flag that allows the MXO Tag to retry the binding of both on-click Capture points and Optimization points, in the format:
or
|
timeoutMS |
Optional. A number, in milliseconds, that determines the maximum amount of time the MXO Tag waits before abandoning attempts to show any optimizations on a page. The time to compare is calculated as the difference, in milliseconds, between page load and interaction response from MXO. Medallia recommends choosing a value no higher than the default (1050).Format:
Note: Single page applications that send interactions over time should set this value to 0 (zero).
Setting the value to 0 means that MXO will not determine if it's too late to show optimizations. MXO will show all optimizations, regardless of page load and interaction response timing, which may lead to an increase in optimization flicker for users that would otherwise not have been presented an optimization. |
Returns
A promise into which a data object is passed, when the REST call completes. This is similar to the object returned by the sendInteraction() method.
sendProperties
customerApi.sendProperties(interactionPath, properties);
The sendProperties() method sends additional data about the current customer or context to MXO. Typically, this would include additional, dynamic, data not directly visible on the page. It does not trigger any Activity Capture or Optimization Points for the matched Interaction but will update the data sent matching any Attribute Capture Points.
Use cases
- You want to send additional data to MXO about the customer who is currently logged in, but that information is not actually "presented" on the screen. For example, information about their customer identifier or other available insights.
- You want to send information about the actual content presented to a customer where multiple content variations are available for a single context.
Required Input
Parameter | Description |
---|---|
interactionPath | Required. The path of the Interaction Point to send to MXO. This will be appended to the current Touchpoint. You can either send the path for the current context or a fully qualified URI, including the base Touchpoint. |
properties |
Required. A JavaScript object containing your properties, in the format:
|
Returns
A promise into which a data object is passed, when the REST call completes. This is similar to the object returned by the sendInteraction() method.
sendResponseCode
customerApi.sendResponseCode(responseCode);
The sendResponseCode() method registers a response code for one of the Actions returned by the previous sendInteraction() call.
Use case
You want to register the customer response to an Action returned on a web Touchpoint.
By default, only positive responses, on click, are registered for web Touchpoints.
Required Input
Parameter | Description |
---|---|
responseCode | A string containing the response code that enables the selected Action to register the response. The sendInteraction() method sends response codes with any Actions returned for Optimization Points. |
Returns
A promise into which a data object is passed, when the REST call completes. This is similar to the object returned by the sendInteraction() method.
getTID
customerApi.getTid();
The getTid() method returns the TID for the customer identified in the current browser, making it available within JavaScript, to, for example, share with other solutions.
Use case
You want to send the TID for the current customer to a third party advertising solution.
generatePixelURL
customerApi.generatePixelUrl(interactionPath, properties);
The generatePixelUrl() method returns the MXO Pixel URL for the current customer and Space. This method does not make any calls to MXO, but assembles a string URL containing all the information necessary to trigger the specified Interaction.
Use case
You want to synchronize MXO TID with the identifier used by a third-party advertising platform. This involves sending the TID to that advertising platform, and the advertising platform sending their customer identifier back to MXO, enabling MXO to associate that customer identifier with the TID. This is known as cookie-syncing.
In normal cookie-syncing integrations, the URL generated by the generatePixelUrl() method is encoded and passed as a parameter to the cookie-sync API of the advertising platform. A specially named property value is provided to the generatePixelUrl() method to indicate the substitution token that the advertising platform will replace with its' own tracking id.
Worked Example
// Get tid and pixel URL from MXO Var tid = customerApi.getTid(); // tid now e4fb914c-1f4c-405d-82c4-d358915a958e var pixelUrl = customerApi.generatePixelUrl('/store-ad-id', {"ad-id" : "ADIDTOKEN" }); // pixelUrl now https://eu2.thunderhead.com/one/rt/web/onetag/pixel/ // ONE-NWPAYPVCJA-1444?tid=e4fb914c-1f4c-405d-82c4-d358915a958e& // uri=https://www.site.com/store-ad-id?ad-id=ADIDTOKEN // Add the MXO tid and the pixel URL to the Ad Platform's cookie syncing API var syncURL = 'https://track.adplatform.com/sync?id=' + tid + '&url=' + pixelUrl // Call Ad Platform's Cookie Syncing URL // After triggering the cookie syncing API, the ADIDTOKEN will be replaced // by the Ad Platform, and subsequently the pixel URL // will be triggered at the following URL: https://eu2.thunderhead.com/ // one/rt/web/onetag/pixel/ONE-NWPAYPVCJA-1444?tid=e4fb914c-1f4c-405d-82c4- // d358915a958e&uri=https://www.site.com/store-ad-id?ad-id=id-from-ad-platform
Required Input
Parameter | Description |
---|---|
interactionPath | Required. The path of the Interaction Point to send to MXO. This will be appended to the current Touchpoint. You can either send the path for the current context or a fully qualified URI, including the base Touchpoint.For example /store-ad-id might be used as the path to trigger a specific Interaction Point that is setup to capture the tracking ID sent by the advertising platform. |
properties |
Optional. A JavaScript object containing your properties, in the following format:
|