Salesforce Marketing Cloud allows you to set your contacts on a marketing journey with timed communications and logic-based actions. It also gives you the ability to track what happens to those contacts over time. The catch is you're only allowed 30 days of tracking data. For some larger campaigns, or even for historical comparisons, 30 days of data just isn't enough. Luckily, by leveraging the Marketing Cloud REST API and its automations, we can store as much of that data as we'd like for access at any time.
Getting the Data
The most challenging part of saving the journey history data is actually getting to it. There is not a documented endpoint for grabbing journey history data, but that doesn't mean it can't be done.
The endpoint to grab the data from is "interaction/v1/interactions/journeyHistory/." This returns an array of the data in the journey history, just like you'd expect from other SSJS queries or REST API calls.
Example Call:
var searchPage = 1 ; var pageSize = 2 ; var auth = authorizationToken ; var var headerNames = ['Authorization']; var headerValues = ['Bearer ' + auth]; var url = orgEndPoint + '/interaction/v1/interactions/journeyHistory/search?$page='+searchPage+'&$pageSize='+defaultPageSize ; var payload = { Start: "2021-06-15T08:00:00.611Z", End: "2021-06-18T10:01:35.611Z" }; payload = Stringify(payload); result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
You can specify the record page you'd like to retrieve and the number of records returned in a single call by using the "interaction/v1/interactions/journeyHistory/search" endpoint with $page and $pageSize parameters. We found that requesting 1,000 records at a time was the most efficient and least likely to cause problems.
Example Response:
{ "count": 3879, "page": 1, "pageSize": 2, "links": {}, "items": [ { "id": "1111111111", "mid": 123456, "eventId": "1111111111-1111-aa11-aa11-1111111111", "definitionId": "1111111111-1111-aa11-aa11-1111111111", "definitionName": "Journey Name", "eventName": "Event Name ", "contactKey": "1111111111", "transactionTime": "2021-06-11T13:00:10.001Z", "status": "Complete", "clientStatus": "Success", "message": "", "activityId": "00000000-0000-0000-0000-000000000000", "activityType": "Other", "definitionInstanceId": "1111111111-1111-aa11-aa11-1111111111", "createdDate": "2021-06-11T10:00:09.661-06:00", "activityBatchInstanceId": "1111111111-1111-aa11-aa11-1111111111", "result": { "status": "Continue", "outcome": {}, "tags": [], "messages": [] } }, { "id": "1111111112", "mid": 123456, "eventId": "1111111111-1111-aa11-aa11-1111111111", "definitionId": "1111111111-1111-aa11-aa11-1111111111", "definitionName": "Journey Name", "eventName": "Event Name ", "contactKey": "test@apitest.com", "transactionTime": "2021-06-11T13:00:10.001Z", "status": "Complete", "clientStatus": "Success", "message": "", "activityId": "1111111111-1111-aa11-aa11-1111111111", "activityType": "EMAILV2", "activityName": "Email", "definitionInstanceId": "1111111111-1111-aa11-aa11-1111111111", "createdDate": "2021-06-11T10:00:09.661-06:00", "activityBatchInstanceId": "1111111111-1111-aa11-aa11-1111111111", "result": { "status": "Continue", "outcome": {}, "tags": [], "messages": [] } } ] }
What About Orgs with Several Business Units?
Many organizations using Marketing Cloud have at least one business unit other than their primary one. Depending on how your organization separates data, you may want to separate out the saved journey history for each business unit. At the least, you'll want to save the journey history for all your business units.
To switch which organization you want to retrieve data for, it's as simple as getting a new access token from that business unit. Since authentication requires the MID, you can simply pass each one in turn to get that business unit's data.
Avoiding Timeouts
Depending on how much your organization uses journeys and how active your contacts are, you may end up with a lot of data to retrieve and store. Since you won't want to replicate your SSJS several times for each org, that means all the data needs to be recorded within the thirty-minute timeout window.
There are two strategies that will help keep your automation running quickly. The first is the tried and true database rule: limit your queries. Keep track of the latest journey history line you've synced for each business unit and only query from that timestamp on. This will keep the number of records returned much more manageable.
Second, you'll want to record your data in bulk. Writing data takes time, so bundling the returned records into a large array and using the SSJS Rows.Add() function to add up to 2,500 (again, we recommend 1,000 as that seems to perform more reliably) records at a time, which will help keep your automation running efficiently.
Conclusion
The data integration and reporting available in Marketing Cloud is what makes it such a powerful marketing tool. While saving all your journey history requires some work, the result is significantly more data that users can analyze to create more useful customer journeys. For help gaining additional insight into the success and trends in your journeys, please contact us.
Need help with your Salesforce digital transformation? Contact us today to discuss Salesforce consulting, implementation, development, and support!
Download the Saving Journey History in Marketing Cloud Sample File File
Please complete the form below to download your FREE FileMaker file.