All Collections
MoEngage
MoEngage - Personalization with Content APIs
MoEngage - Personalization with Content APIs
Updated over a week ago

If you've read the article on Deploying an Experiment in MoEngage, you'll be familiar with the standard approach using Content APIs.

As a reminder, and for comparison, the standard approach uses a code snippet in the subject line that looks something like this:

{%set variants = ContentApi.phraseeRealtimeAPI({({"params":{"campaign_id":"PhAK33xPer1m3nT1d4d0cUM3NtAt1oN","recipient_id":"{{UserAttribute['ID']}}","delivery_id":"{{CampaignAttribute['_id']}}"},"static_params":{},"dynamic_params":{},"request_body":{}})})%}{{variants.variant_text|default("HELP! I am stuck in Phrasee Towers writing Documentation!")}}

However, what happens if you want to use some personalization, like first name, in the subject line?

Replacer Variables

The answer lies in an extension to the Content API parameters. What you will do is declare three parameters for each personalization field and add them to the "params" object of the Content API function. Sounds complicated, but this guide will take you through it.

The three parameters

The three parameters you'll need for each field are:

  • replacer_variable - The variable in the Phrasee language variant for which MoEngage will search. You must not include any brackets or punctuation for this variable.

  • replacer_value - MoEngage will use this to replace what it finds from your replacer_variable.

  • replacer_default - This is the value MoEngage will use if it doesn't find any data to display from the personalization field you've selected.

Appending the parameters

Once you understand what each of those parameters is going to be used for, it becomes quite straightforward to decide what they need to contain.

You'll need to add them to the "params" object of the Content API function.

As an example, let's say you wanted to use an MoEngage Handlebars personalization field in the Phrasee variant called firstName.

You would need to configure the Content API function to contain the following parameters:

"replacer_variable":"firstName","replacer_value":"{{UserAttribute['firstName']}}","replacer_default":"Supporter"

Notice that the replacer_variable is simply the text that appears in the Phrasee variant. You can discuss with your Phrasee Customer Success team which replacer variables you want to generate in your content, and they'll make sure they are added to your language configuration.

The replacer_value has then been added as you normally would add a personalization field to MoEngage. In this case, it's {{UserAttribute['firstName']}}.

Finally, the replacer_default has been populated as Supporter. This will be used in case MoEngage is unable to find any data in the firstName field for any subscriber in particular.

When added to the Content API function, it will look something like this:

{%set variants = ContentApi.phraseeRealtimeAPI({({"params":{"campaign_id":"PhAK33xPer1m3nT1d4d0cUM3NtAt1oN","recipient_id":"{{UserAttribute['ID']}}","delivery_id":"{{CampaignAttribute['_id']}}","replacer_variable":"firstName","replacer_value":"{{UserAttribute['firstName']}}","replacer_default":"Supporter"},"static_params":{},"dynamic_params":{},"request_body":{}})})%}{{variants.variant_text|default("HELP! I am stuck in Phrasee Towers writing Documentation!")}}

Multiple personalization fields

If you're interested in using more than one personalization field in your Phrasee variants, you can simply append another trio of parameters to the params section as in the below example, that also replaces the variable phraseeCity:

{%set variants = ContentApi.phraseeRealtimeAPI({({"params":{"campaign_id":"PhAK33xPer1m3nT1d4d0cUM3NtAt1oN","recipient_id":"{{UserAttribute['ID']}}","delivery_id":"{{CampaignAttribute['_id']}}","replacer_variable":"firstName","replacer_value":"{{UserAttribute['firstName']}}","replacer_default":"Supporter","replacer_variable":"phraseeCity","replacer_value":"{{UserAttribute['City']}}","replacer_default":"London"},"static_params":{},"dynamic_params":{},"request_body":{}})})%}{{variants.variant_text|default("HELP! I am stuck in Phrasee Towers writing Documentation!")}}

Ultimately, you can add as many personalization fields as you like.

Did this answer your question?