Rokt
Rokt object provides the entry point to integrate with Rokt's solution.
Methods
closeAll
▸ closeAll(): void
Close/Unload all placements on the page
Returns: void
getPlacements
▸ getPlacements(): Promise‹Array‹Placement››
Returns a list of selected placements
Returns: Promise‹Array‹Placement››
hashString
▸ hashString(value
: string): Promise‹string›
Convenience method hashing a string using SHA-256. Since Rokt manipulates string before hashing it is recommended to use the provided method instead of implementing on your own.
Parameters:
Name | Type | Description |
---|---|---|
value | string | string to hash |
Returns: Promise‹string›
init
▸ init(configuration
: Configuration): void
Sets information allowing to identify you or your consumer.
see
Configuration on details of available parameters.
Parameters:
Name | Type | Description |
---|---|---|
configuration | Configuration | Configuration object |
Returns: void
onFailure
▸ onFailure(failureCallback
: function): void
Accepts a callback which will be triggered when Rokt object fails to load/cannot be displayed correctly. For example, this scenario can happen when encountering very old browser that is not supported by Rokt as per agreement with client.
example
rokt.onFailure((reason) => {
// Use this hook to display error or navigate to another page
});
Parameters:
▪ failureCallback: function
Callback to be triggered when Rokt object is ready
▸ (reason
: string): void
Parameters:
Name | Type |
---|---|
reason | string |
Returns: void
onLoaded
▸ onLoaded(onLoadedCallback
: function): void
Accepts a callback which will be triggered once Rokt object has been loaded and is ready to use. Callback will be triggered immediately if Rokt object is already ready.
You can invoke this method multiple times each time passing a unique callback. They will be all executed in the order they were passed once Rokt object is ready to integrate. This approach may be useful in case of Single Page Applications in which integration points may happen in multiple places in the JavaScript code.
example
rokt.onLoaded((rokt) => {
// Now you can interact with Rokt object
});
Parameters:
▪ onLoadedCallback: function
Callback to be triggered when Rokt object has been loaded
▸ (rokt
: Rokt): void
Parameters:
Name | Type |
---|---|
rokt | Rokt |
Returns: void
setAttributes
▸ setAttributes(attributes
: Attributes): void
Sets attributes which allow Rokt to better tailor offer to a consumer. Those attributes may include consumer email, first name, last name, etc.
Depending on your catalog provider, additional information may be required by Rokt to be able to retrieve catalog items, e.g. for ticketing partners eventId
is required.
Rokt.setAttributes performs a shallow merge of passed attributes into the existing attributes.
Since passing browser's user agent is required attributes store its value under userAgent
property by default.
default
{
userAgent: 'Mozilla/5.0 (...)', // window.navigator.userAgent value
}
Parameters:
Name | Type | Description |
---|---|---|
attributes | Attributes | Dictionary with data such as first name, last name, email, etc. |
Returns: void
setFulfillmentAttributes
▸ setFulfillmentAttributes(attributes
: Attributes): void
Sets attributes that remains unknown by Rokt until the user accepts any of the offers.
Rokt.setFulfillmentAttributes performs a shallow merge of passed attributes into the existing attributes.
Parameters:
Name | Type | Description |
---|---|---|
attributes | Attributes | Dictionary with data such as first name, last name, email, etc. |
Returns: void
triggerPageChange
▸ triggerPageChange(options
: TriggerPageChangeOptions): void
Re-triggers placement selection for a new page.
In case of SPA integrations, Rokt's solution may be displayed on multiple pages or loaded on a page which does not initially shows placements to a user. In this case, Rokt relies on partner to trigger the method to let Rokt know when user reaches page we meant to display placements on.
Parameters:
Name | Type | Description |
---|---|---|
options | TriggerPageChangeOptions | Options for new page. |
Returns: void