Basic Methods
Sets the unique identifier in order to log data.
DYReact.setSecret(secretKey,callback)
Parameters
- secretKey: String key obtained in the Experience OS console
- callback: A function of type (state: ExperimentsState) that is called with the results of the Dynamic Yield SDK initialization results.
Examples
DYReact.setSecret('569bb4b05f74hf64315e122c', state => {
console.log(`DY ready with state: ${state} `);
});
User Data
Used to identify the user across platforms (e.g. web, iOS, CRM, email); We recommend calling this method wherever the user enters their customer ID (e.g. checkout).
DYReact.identifyUser(userData, callback)
Parameter
- userData: A JSON object that holds basic identification attributes about the user.
- callback: A function of type () that is called after a user is identified successfully.
Example
DYReact.identifyUser(
{
type: 'he',
cuid:
'c0e93cee791b35af528a825f6476e8108e5f03e481ee39800a31a75559cdba2e',
},
err => {
if (err) {
console.log(`got error: ${err}`);
} else {
console.log('user identified');
}
},
);
Indicates that a user has consented to allow Dynamic Yield to collect and use their personal data.
- Opting out prevents future data collection from the current device/browser from all sections of the account, across all domains. This method overrides any past opt-in methods.
- If the visitor had opted out in the past, opting in will allow data collection moving forward.
For more details, see Visitor Data Privacy Management (GDPR Support).
Example
DYReact.consentOptIn()
Indicates that a user does not want Dynamic Yield to collect and use their personal data.
- Opting out prevents future data collection from the current device/browser from all sections of the account, across all domains. This method overrides any past opt-in methods.
- If the visitor had opted out in the past, opting in will allow data collection moving forward.
For more details, see Visitor Data Privacy Management (GDPR Support).
Example
DYReact.consentOptOut()
Analytics
Reports an event to Dynamic Yield.
DYReact.trackEvent(eventName, eventParams, callback)
Parameters
- eventName: The unique name of the event as maintained in the Experience OS console
- eventParams: Event parameters JSON object
- callback: A function of type (name: String) that is called when an event is tracked successfully. This is used to wait for the event data to be available before running something that is dependent on that data.
Example
DYReact.trackEvent('button clicked', {buttonName: 'login'}, eventName => {
if (eventName) {
console.log(`event ${eventName} processed`);
}
});
Reports an application page view to the Dynamic Yield server.
DYReact.pageView(pageUniqueID, context, callback)
Parameters
- pageUniqueID: Unique identifier of the page as maintained in the application
- context: The current screen’s context as a JSON object.
- callback: A function of type (name: String) that is called when a pageview is tracked. This is used to wait for the data to be available before running something that is dependent on that data.
Example
DYReact.pageView('homepage', {lng: 'en_US', type: 'HOMEPAGE'}, pageName => {
if (pageName) {
console.log(`page ${pageName} processed`);
}
});
Sets an evaluator value, will remain valid until set again or until the session ends.
DYReact.setEvaluator(evaluatorID,values,persistent,callback)
Parameters
- evaluatorID: The evaluator ID from the Experience OS console
- values: Array of the evaluator value(s)
- persistent: true to save the evaluator value between sessions, false to clear value when a new session starts
- callback: A function of type () that is called when an evaluator value is set. This is used to wait for the data to be available before running something that is dependent on that data.
Example
DYReact.setEvaluator('15665', ['signedIn'], true, () => {
console.log('Evaluator is set');
});
Variable Sets
Returns the value assigned to a variable name specified in parameter smartVariableID. The value is maintained in the Experience OS console. If there is no value assigned, the value specified in parameter defaultValue will be used.
DYReact.getSmartVariable(smartVariableID,defaultValue,callback)
Parameters
- smartVariableID: The name of the variable as maintained in the Experience OS console
- defaultValue: The value that should be assigned to the variable in case no value is returned (e.g.the variable has been archived or deleted in the Experience OS console). The value can be null, but make sure that this does not negatively impact your app.
- callback: A function of type (variableName, value) that is called when a variable value is retrieved.
Example
DYReact.getSmartVariable('backgroundColor', '#000000', (varName, value) => {
console.log(`smartVar: ${varName} returned ${value}`);
});
Recommendations
Get the recommended items for a given widget id in a specified context.
DYReact.sendRecommendationRequest(widgetID,context,callback)
Parameters
- widgetID: The recommendation widget ID as maintained in the Experience OS console
- context: The current screen’s context, see details in Dynamic Yield Context Object
- callback: A function of type (results: [JSONObject], widgetID: String) that is called when the recommendation response is returned with the recommended products.
Example
DYReact.sendRecommendationRequest(
'31002',
{type: 'HOMEPAGE'},
(rcom, widgetID) => {
console.log(`widgetID: ${widgetID} returned ${JSON.stringify(rcom)}`);
},
);
DYReact.sendRecommendationRequest(
'31002',
{type: 'PRODUCT', data: ['productSKU']},
(rcom, widgetID) => { console.log(`widgetID: ${widgetID} returned ${JSON.stringify(rcom)}`);
},
);
Reports the identifier of a recommended item clicked by the user within a given recommendation widget to Dynamic Yield.
DYReact.trackRecomItemClick(widgetID, sku)
Parameters
- widgetID: The recommendation widget ID used for receiving the recommendations items presented to the user
- sku: The identifier of a recommendation items clicked by the user
Example
DYReact.trackRecomItemClick('31002', 'aaa01');
Reports a list of recommended items real impressions (i.e. were visible to user) within a given recommendation widget to Dynamic Yield.
DYReact.trackRecomItemRealImpression(widgetID, skus)
Parameters
- widgetID: The recommendation widget ID used for receiving the recommendations items presented to the user
- skus: An array of identifiers of recommendation items presented to the user
Example
DYReact.trackRecomItemRealImpression('31002', ['aaa01', 'aaa02']);