1. Tracking

Set up IDENTITY events

Version:

You can use the Cloud SDK events package to capture IDENTITY events. IDENTITY events are typically captured in registration, login, and signup forms and are used to resolve the identity of an anonymous site visitor of your app.

In this topic, you'll start capturing events on the browser side, in the out-of-the-box Promo component in a JSS Next.js app (JSS version 22.2). Note that in production, you will most likely capture IDENTITY events in forms, not in the Promo component. This topic shows how to set up the event so you can later capture them in the components of your choice.

Before you begin

To capture IDENTITY events on the browser side:

  1. In Promo.tsx, at the top of the file, import the identity function from the browser module of the events package:

    import { identity } from "@sitecore-cloudsdk/events/browser";
  2. In Promo.tsx, in the Default component, within the return statement, add a React onClick event handler to the topmost JSX element:

    // ...
    return (
      <div
        onClick={handleClick}
        className={"..."}
        id={"..."}
      >
    {/*...*/}
    )
    Note

    In production, place the event listener on a clickable element such as a <button>, instead of a <div>.

  3. In the Default component, on the first line of the function body, paste the following code, then save your changes:

    function handleClick() {
      identity({
        identifiers: [
          {
            id: "<YOUR_ID>", // example: "[email protected]"
            provider: "<YOUR_PROVIDER>" // example: "email"
          }
        ]
      });
      console.log("Sent IDENTITY event.");
    }

    This code sends an IDENTITY event every time the Promo component is clicked.

    Tip

    In production, we recommend you pass your correct identity system data and pass other event data to the identity function to make sure that your web app captures rich event data.

  4. In your terminal, enter npm run start:production to start your JSS Next.js app.

    Tip

    If your app fails to compile due to linting errors, consider disabling ESLint rules.

  5. In your web browser, navigate to your JSS Next.js app, typically at http://localhost:3000.

  6. In your web browser's developer tools, on the Network tab, in the Filter field, paste the following URL: edge-platform.sitecorecloud.io.

    Doing this lists the network requests made to Sitecore.

  7. Reload your webpage to start recording network activity.

  8. On your webpage, click the Promo component.

    The click triggers the IDENTITY event.

  9. In the developer tools, on the Network tab, in the list of requests, click the last POST request with a status of 201 Created and a name that starts with events.

    This is the network request made when you clicked the Promo, and it contains the event data for the IDENTITY event that you captured.

  10. In the request details pane, click the Payload tab for the request.

  11. In the request payload, copy the value of the browser_id key. You'll use it to find the captured events in your Sitecore DXP products.

    The browser ID uniquely identifies a site visitor and associates captured events with that visitor. In this example, the browser ID identifies you and associates you with the actions you took: viewing the webpage and clicking the Promo component.

:::

You're now tracking IDENTITY events in your web app as site visitors interact with your site. You can now find the events in your Sitecore DXP products. The collected event data will drive, for example, web analytics, segmentation, personalization, and more.

Next, you can:

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