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.
-
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.
-
Enter a unique and intuitive name for the export and click Create.
-
In the Audience section, click Add segment, then select the segment for this export.
-
Click Output format > Define output.
-
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.
-
On the Define output screen, on the Output structure tab, click Add column.
-
In the newly added column, in the Header field, enter email.
The header will appear in the first row in the CSV output.
-
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.
TipUsing a utility function, you can hash email addresses so they're securely exported.
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.
-
On the Define output screen, click JavaScript and paste the following code:
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
orderRefandorderStatusto include the order data in the output in the next step. -
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.
-
-
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.
-
On the audience export page, click Test > Test scenario.
-
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.
-
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, anorderRef, and anorderStatusheader, and will include the email addresses and the order data of your audience.NoteIf 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.
-
Close the Test window.
-
Click Schedule.
-
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.
-
-
On the Summary pane, review the schedule details.
-
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.