Run a triggered personalization

After a triggered personalization is Live, your application starts it by sending the triggering event. SitecoreAI then runs the configured action. The event call does not return that action's result.

Use the Integration guide in SitecoreAI for instructions and code specific to the selected personalization.

You can run a triggered personalization using Content SDK, REST API, or Cloud SDK.

Open the Integration guide

To open the Integration guide:

  1. In the navigation menu, click Optimization.

  2. In the left sidebar, click Tests & personalizations.

  3. Select Triggered.

  4. Select the live triggered personalization you want to run.

    The Configuration page opens.

  5. In the right pane, click the Connect tab.

  6. Click Open guide.

    The Integration guide pane opens.

  7. Select the integration method that matches your application:

Note

The Integration guide provides the request or code specific to the selected triggered personalization and its triggering event.

Content SDK

Before you begin

Make sure:

Your application uses Content SDK 2.x and is initialized with the events plugin. For details, see the Content SDK initialization guide.

To send an event for a triggered personalization from a Content SDK application:

  1. In the Integration guide pane, click the Content SDK tab.

  2. In Step 1 - Send the <EVENT_IDENTIFIER> event, click the copy icon to copy the TypeScript or JavaScript code.

  3. Add the code to your application and run it whenever the event occurs.

    The SDK reuses the visitor's client ID and site information from initialization.

    For example:

    import { event } from "@sitecore-content-sdk/events";
    
    await event({
       "channel": "WEB",
       "language": "EN",
       "type": "<EVENT_IDENTIFIER>"
    });
    Note

    Set type to the same event name configured on the trigger. The sample sets channel to WEB for a website. For a mobile app, use MOBILE_APP. For a kiosk, use KIOSK.

REST API

Before you begin

Make sure:

To send an event for a triggered personalization using the REST API:

  1. In the Integration guide pane, click the REST API tab.

  2. In the Sitecore context ID field, enter the context ID for your environment.

    If necessary, click View context IDs to find the ID.

  3. In the Analytics identifier list, select the analytics identifier to use for tracking.

  4. In Step 1 - Get a client ID, click the copy icon to copy the request template and send the request.

    A client ID identifies the visitor across requests. For a new visitor, retrieve the id from the response, store it, and reuse it as <CLIENT_ID> in subsequent requests for the same visitor.

    For example:

    curl -X POST '<baseURL>/v1/events/api/dp/v1/clients'' \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json' \
      -H 'x-sitecore-contextid: <SITECORE_CONTEXT_ID>' \
      --data-raw '{
        "clientKey": ""
      }'

    Send this request from the visitor's browser or device so SitecoreAI can derive location and device information from the request.

  5. In Step 2 - Send the <EVENT_IDENTIFIER> event, click the copy icon :mdiContentCopy

    copy the request template and send the event whenever it occurs in your application.

    Use the analytics identifier selected in step 3 and the client ID obtained in step 4.

    For example:

    curl -X POST '<baseURL>//v1/events/api/dp/v1/events' \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json' \
      -H 'x-sitecore-contextid: <SITECORE_CONTEXT_ID>' \
      --data-raw '{
        "clientKey": "",
        "clientId": "<CLIENT_ID>",
        "siteId": "<ANALYTICS_IDENTIFIER>",
        "channel": "WEB",
        "language": "EN",
        "name": "",
        "type": "<EVENT_IDENTIFIER>",
        "customData": null
      }'

Cloud SDK

Before you begin

Make sure:

Your application uses the Sitecore Cloud SDK and is initialized with the events package. For details, see the Cloud SDK initialization guide.

To send an event for a triggered personalization from a Cloud SDK application:

  1. In the Integration guide pane, click the Cloud SDK tab.

  2. In Step 1 - Send the <EVENT_IDENTIFIER> event, click the copy icon to copy the TypeScript or JavaScript code.

  3. Add the code to your application and run it to request the triggered personalization.

    The SDK reuses the visitor's client ID and site information from initialization, so you only need to specify the personalization's friendly ID and channel.

    For example:

    import { personalize } from "@sitecore-cloudsdk/personalize/browser";
    
    const personalizeResponse = await personalize({
      channel: "WEB",
      friendlyId: "triggeredpersonalization",
    });

    Set type and channel the same way as in the Content SDK sample.

If you have suggestions for improving this article, let us know!