Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore CDP
Data availability
Managing your account
Managing system settings
Managing guests
Batch segmentation
Data browser
Audience export
Dashboards
Developer center
AI in CDP
Glossary
  • Sitecore CDP
  • Audience export
  • Walkthroughs for working with audience exports
  • Export the deltas of an audience with a completed order

Export the deltas of an audience with a completed order

This walkthrough describes how to export the deltas of an audience. In this scenario, the audience completed an order on your website in the previous 24 hours. This walkthrough assumes that you have a Scheduled or Live segment with at least one segment member.

This audience has recently purchased something on your website, so there's no need to include these guests in your next paid-media ad campaign. Using the exported data, you can add this audience to an exclusion list to make sure the campaign doesn't run for them. This helps reduce campaign costs and engage with only those audiences that haven't recently completed an order.

This walkthrough describes how to:

  • Create an audience export.

  • Include email addresses in the output.

  • Use JavaScript to include order data in the output.

  • Test, then run the export instantly.

Create an audience export

The first step to exporting an audience is to create an export.

  1. On the navigation menu, click Audience export > Audience export > Create export > Delta export.

    A delta export runs once a day. The first export contains the full audience that you specify in a later step. Subsequent exports contain data only for those guests in the audience that have been added to or removed from the segment since the previous run.

  2. Enter a unique and intuitive name for the export and click Create.

  3. In the Audience section, click Add segment, then select the segment for this export.

  4. Click Output format > Define output.

  5. On the Define output screen, on the File format tab, click CSV.

Include email addresses in the output

After choosing the file format, you stay on the Define output screen to choose what data to include in the output of the audience export.

  1. On the Define output screen, on the Output structure tab, click Add column.

  2. In the newly added column, in the Header field, enter email.

    The header will appear in the first row in the CSV output.

  3. In the same column, in the Attribute value field, enter ${guest.email}.

    This is a reference to the email address of every guest in the segment. The email addresses will appear in the email column in the CSV output.

    Tip

    Using a utility function, you can hash email addresses so they're securely exported.

    Including the email address in the output structure of an audience export.

Use JavaScript to include order data in the output

After including email addresses in the output, you stay on the Define output screen to compute order data and include it in the output.

  1. On the Define output screen, click JavaScript and paste the following code:

    RequestResponse
    (function () {
      load("classpath:moment.js");
    
      // Get guest's orders
      var orders = guest.orders;
      var orderRef = "";
      var orderStatus = "";
    
      // Get yesterday's date
      yesterdayDate = moment.utc().subtract(1, "day").format("YYYY-MM-DD");
    
      for (var orderCount in orders) {
        var orderDate = moment(orders[orderCount].orderedAt).format("YYYY-MM-DD");
        // Log last order date to the console
        console.log(orderDate);
        // Check if order date matches yesterday's date
        if (orderDate === yesterdayDate) {
          orderRef = orders[orderCount].referenceId;
          orderStatus = orders[orderCount].status;
        }
      }
      
      // Return the order data in the "orderRef" and "orderStatus" variables. Then, reference them as ${jsResult.orderRef} and ${jsResult.orderStatus} on the Output structure tab.
      return { orderRef: orderRef, orderStatus: orderStatus };
    })();

    This script searches for an order in the previous 24 hours. If found, it returns the order reference and order status. You'll use the object key names orderRef and orderStatus to include the order data in the output in the next step.

  2. On the Define output screen, click Output structure and create the following columns:

    • A string column where the Header is orderRef and the Attribute value is ${jsResult.orderRef}.

    • A string column where the Header is orderStatus and the Attribute value is ${jsResult.orderStatus}.

    The headers will appear in the first row in the CSV output. The attribute values are references to the computed order data for every guest in the segment.

  3. Click Save, then close the Define output screen.

Test, then run the export instantly

After including order data in the output, you test the export, then run it instantly.

  1. On the audience export page, click Test > Test scenario.

  2. On the Test scenario tab, click in the search field, and then click Customer.

    This selects a random guest for testing the export. Alternatively, you can select a guest from the exact segment you're using for this export.

  3. Click Test. After the test runs, in Response > Output, you should see an output similar to:

    RequestResponse
    "email","orderRef","orderStatus"
    "[email protected]","B-321741","PURCHASED"

    This shows that your output will be in the CSV format containing an email, an orderRef, and an orderStatus header, and will include the email addresses and the order data of your audience.

    Note

    If you don't see some of this data, that's because the guest profile of the guest selected for the test doesn't contain this data. In production, make sure that the data you reference from the guest profile is available in the guest profile.

    You're now ready to export your audience.

  4. Close the Test window.

  5. Click Schedule.

  6. On the Schedule audience export screen, specify the following settings:

    • Set the Start date to Tomorrow.

    • Set the End date to Run forever.

    • Set Run time to 6:00 am UTC.

  7. On the Summary pane, review the schedule details.

  8. Click Schedule. The export is now scheduled to run every day starting tomorrow.

After the audience export finishes running, if your administrator enabled downloading the output directly from Sitecore CDP, you can do this on the same webpage: on the Activity tab, in the Finished exports section, click Download output. Alternatively, you can get an email notification with download instructions or send a webhook notification to external APIs or integration tools. See Accessing the exported data.

Next steps

You've now successfully set up daily delta exports of an audience's email addresses and order data from Sitecore CDP. Every day, the export will contain a different group of guests, depending on their order history from the previous 24 hours. Using the exported data, you can exclude this audience from your next paid-media ad campaign.

Next, you can:

  • Find out what other data you can include in the output.

  • Use JavaScript to compute other custom data. You can write the code manually, or generate it with the Code Assistant using natural language.

  • Understand the contents of the output.

  • Consider the difference between full and delta exports.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore