Destination connection
Create a new Connected App in Salesforce. Find the App Manager in setup, and click New Connected App at top right. Enable OAuth settings and set the Callback URL to “https://oauth.pstmn.io/v1/callback” to allow testing interactive flows with Postman. Select appropriate scopes, e.g. api, refresh_token. Retrieve the Client ID and Secret once created.
Create a new Connection of type Destination in Sitecore CDP. Use OAuth2 authentication with the following settings:
Token URL: https://<salesforce.domain>/services/oauth2/token
Client ID: from Connected App
Client Secret: from Connected App
The Salesforce refresh_token or password flows can be used here. Click Show URL encoded form and add the required values.
Refresh token flow
grant_type: refresh_token
refresh_token: (perform authorization code flow with Postman or other client and copy the token)
Password flow
grant_type: password
username: (Salesforce username)
password: (Salesforce password)
The endpoint should be https://<salesforce.domain>/services/apexrest/cdp4sapi/guestdata.
Audience Template
Create a new Real-Time Audience Template under Library > Audience Templates. This allows restricting data sent to Salesforce to avoid unnecessarily exceeding API limits. Create a JavaScript function as follows to limit to identified (Customer type) Guests only:
Code Block | ||
---|---|---|
| ||
// Include only identified (Customer type) Guests.
(function () {
return (guest.guestType == 'customer');
})(); |
Add further restrictions if you have specific requirements.
Triggered Experience
Create a Full Stack Triggered Experience to automatically send Guest data to Salesforce. For the trigger we recommend:
Session Closed to send when a Guest session ends, or
Custom Trigger on the IDENTITY event to send as soon as the Guest is identified, or
both of the above
Limit the Audience using the Audience Template created above.
Create a Webhook variant that sends to the Destination Connection created above. Create the API response with the following Freemarker template:
Code Block |
---|
<#-- Output all Guest data. -->
${toJSON(guest)} |
Interactive Experience
Create a Full Stack Interactive Experience with the same Audience Template and API response as above. Note the friendlyId value for configuration in Salesforce - this Experience will be used to retrieve Guest data on demand Full Stack Experiences.