Szymon Lewandowski website logo
Published on

How to send additional events in Marketing Cloud Personalization

Authors
  • avatar
    Name
    Szymon Lewandowski
    Twitter

Marketing Cloud Personalization - sending additional events in MCP

Usually events are triggered by user and defined in the sitemap. But is this the only way to do this? Here is how you can send multiple events to Marketing Cloud Personalization without adding it to the sitemap. Let's send single, multiple and as many events as you want!

When you need to send additional events or test events?

Events are one of the key components in Marketing Cloud Personalization. We use them to track specific user behavior. We create segments from events, and we build rule-based Web Campaigns with them. Usually events are triggered by user and defined in the sitemap. But what if we want to record additional events in our dataset? And what if we want to add hundreads of them quickly?

During sitemap development, it is normal to define events using sendEvent() function. Then, when user will peform an action that will trigger this event, it will be sent to MCP. After about 10 minutes the event will be populated and available in Actions list and it will be ready to use in campaigns and segments.

But what if we have got a new Web Template with additional sendEvent() in its code? Do we need to trigger Web Campaign with this Template to gather this event? And what if we have dynamic event name with several variables in this Template - will we need to perform all possible sequences to gather all possible event name combinations? What if we clone the whole dataset and want to get all events names that we used in segments? Will we need to manually collect all these events once again?

Fortunately - we won't. 👌

Adding single ad-hoc event from the Marketing Cloud Personalization Web Campaign UI

One simple way to add new action is to add event manually in Web Campaign creation. Just create new Web Campaign, add Action to rules and write your custom event name.

Marketing Cloud Personalization - new action from the Web Campaign

Seems easy, right? Well, but it is not so perfect. Events added manually through Web Campaign creation are not treated as "normal events" that were sent properly from the user. So you can add new action for the Web Campaign, but they won't be saved in the backend. Web Campaign will trigger when this action will be triggered by user, but the value will not be stored unless this will occur.

This option is perfect when you forget to perform one specific event, but already creating a Web Campaign, but not if you want to have this action stored in the backend.

Read also: What is hyper-personalization?

Adding up to 5 events per second with sendEvent in DevTools

Let's move to the proper solution - adding events in the same way that sitemap does this. Interactions Web SDK allows use to use all Evergage or SalesforceInteractions functions through the console. This is the perfect way to send additional events without triggering these events manually through the sitemap.

We can simply trigger sendEvent() function in DevTools and hit enter button. Simple as that. All you need to do is to use proper naming convention, since there are two different namespaces used in MCP (Evergage and SalesforceInteractions). I'll write whole article about these two in the future. :)

Here is our script:

sendEvent()_function_for_Evergage_namespace
Evergage.sendEvent({
        action: "your custom event name"
    });
sendEvent()_function_for_SalesforceInteractions_namespace
SalesforceInteractions.sendEvent({
        interaction: "your custom event name"
    });

There is one tiny catch. You can't trigger more than 5 events in the same moment. MCP has blocking mechanism called Event limitter, that will block additional events performed in about 1 second interval. You can wait with next bulk of events or use setTimeout() or setInterval() JS functions to handle that. But what if you have tens or hundreads of events to trigger? Well, then you have to use the power of API.

Adding multiple events with MCP Event API

Fortunately for us, Salesforce has got special Event API, which allows us to request and send events within specific dataset. You can use simple POST request to send JSON payload. With this method you can bypass Event rate limitter and send as many events as you want with simple use of code. You can use curl as in Developer Docs example or create custom tool that will send bulk of specified events, using for example XMLHttpRequest() object in a simple script, like:

EventAPISend
    var request = new XMLHttpRequest();

    let account: "youraccountname",
    instance:  "yourinstancename",
    dataset: "yourdatasetname",
    url = `https://${params.account}.${params.instance}.evergage.com/api2/event/${params.dataset}`,
    payload = "event=" + btoa(JSON.stringify({ //using btoa() is required
        "action": "your custom event name",
        "user": {
            "id": "your custom user id"
        }
    }))

    request.open("POST", url, true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //don't use 'application/json' due to CORS policy
    request.send(payload)

From where you can get your params? Open MCP, go to your dataset and click on "Gears" -> "Gears" option. The gears menu should pop up. There you can find all params in the URL, such as account, instance and dataset:

Marketing Cloud Personalization - Account, instance and dataset location in URL

  • account - first string in the domain name (youraccountname)
  • instance - second string in the domain name (yourinstancename)
  • dataset - fifth section in the pathname root (yourdatasetname)

There is only a simple snippet with sending one particular event with only the action/interaction name. Of course, you can build an app or more complicated script that could use array of events with loop to send even hundreads of events instantly.

MCP Event API Sender Snippet

And here comes the MCP Event API Sender Snippet. 75-line script that will allow you to send as many events as you want to your dataset. Using simple XMLHttpRequest with forEach() loop, it provides easy and scalable base to send actions, that you can use or create your own solution.

Marketing Cloud Personalization - MCP Event API Sender Snippet UI

Simply download the mcp-event-api-sender-snippet.html file, fill the variable values with your dataset parameters and enjoy. You will find detailed manual in the GitHub repo documentation.

Summary

In Marketing Cloud Personalization, we need to use some tricks to send additional events to our dataset. I hope that presented solutions will help you in your scenario. So, to sum up, what are the pros and cons of each solution?

  1. adding new event in Web Campaign:
    • ✔ perfect when you have to add new event when creating Web Campaign
    • ✔ no coding required
    • ❌ it doesn't add action to the backend:
  2. using sendEvent() in browser console:
    • ✔ perfect for adding several new events to the backend
    • ✔ easy to use with the snippet above 😉
    • ❌ 5 actions per second limit
  3. using MCP Event API:
    • ✔ perfect for adding hundreads of new events to the backend
    • ✔ scalable, elastic solution for huge amount of data
    • ❌ requires higher coding skills

Read also: What is rule-based personalization?

References:

  1. Salesforce Developer Docs - Item Actions
  2. Salesforce Developer Docs - Interactions
  3. Salesforce Developer Docs - Event API Requests
  4. Developer Mozilla Docs - XMLHttpRequest