All Collections
Braze
Braze - Dynamic optimization - Code snippets
Braze - Dynamic optimization - Code snippets

Just a little snippet!

Updated over a week ago

Updated code snippets to include liquid whitespace controls

With your Phrasee token and Braze Currents set up, you're ready to move on to getting your email ready.

Arguably the most important piece of the Brazee dynamic optimization integration (see what we did there?) is the code snippets you'll need to include in your emails.

Our integration leverages a Braze feature known as Connected Content. If you're not familiar with Connected Content, check out Braze's documentation to read all about it.

The tl;dr version is we've created code snippets that works with Braze's Connected Content to dynamically pull language and a tracking pixel into your emails so we can optimize your language in real time using Phrasee's dynamic optimization.

Cool?

The code snippets

You'll need to paste the following code snippet into the Subject field of your Braze email campaign and replace the PASTE YOUR HUMAN CONTROL HERE text with your human control language variant you entered in Phrasee:

{%- connected_content https://realtime.phrasee.co/live/single_variant?campaign_id=<campaign_id>&delivery_id={{campaign.${dispatch_id}}}&recipient_id={{${user_id}}} :method get :headers { "Authorization": "Bearer <token>" } :content_type application/json :no_cache :rerender :save variants -%}{%- comment -%}{%- endcomment -%}
{%- if {{variants.variant_text}} == blank or {{variants.variant_text}} == null -%}
PASTE YOUR HUMAN CONTROL HERE
{%- else -%}
{{variants.variant_text}}
{%- endif -%}

In a previous version of this article, instead of the IF statement, the output was {{variants.variant_text | default: "PASTE YOUR HUMAN CONTROL HERE" }}

As Human Controls may contain personalization variables, which are unsupported in the default function, the approach has now been changed.

And you'll need to paste the following code snippet into the HTML Email Body of your Braze email campaign:

{%- connected_content https://realtime.phrasee.co/live/single_variant?campaign_id=<campaign_id>&delivery_id={{campaign.${dispatch_id}}}&recipient_id={{${user_id}}} :method get :headers { "Authorization": "Bearer <token>" } :content_type application/json :no_cache :rerender :save variants -%}{%- comment -%}{%- endcomment -%}<img src="{{variants.statistics_url}}" width="1px" height="1px">

Generally, we recommend pasting the snippet for the HTML body just above the closing </body> tag in your email.

There are two critical pieces of data you'll need to enter into your code snippets at a minimum:

  • Phrasee Experiment ID - you'll paste this over <campaign_id> in the code snippet

  • Phrasee Connect Server token - you'll paste this over <token> in the code snippet

If you're not sure where to find your experiment ID, we've got an article for that. Your token should have been provided to you during your initial setup. If you can't find it, please reach out to your Phrasee Customer Success Manager.

Below is an example of what the code snippet for the Subject field might look like with a experiment ID and token populated:

And here's what your HTML body snippet might look like:

Personalization

If your Phrasee language contains personalization tags, you'll need to add them to your subject line code snippet in between the {%- comment -%} and {%- endcomment -%} tag.

If you don't include the personalization tags within the comment tags, Braze will not process them properly and (horrors!) they will be rendered as literal text within your subject line.

Our example below shows how a code snippet might be configured with Braze's default first name personalization field:

{%- connected_content https://realtime.phrasee.co/live/single_variant?campaign_id=dFqy9zcZkpCtAejlIFbthPP7&delivery_id={{campaign.${message_api_id}}}&recipient_id={{${user_id}}} :method get :headers { "Authorization": "Bearer PhaKetOKen1B28LFJkDejbI5URTypk5tO1PxSZ3AqI9p1wCJ3GcpNmq6SVwZfUJUUMKEFyv6J9rKvRgEvp30HYSfkJuwGdhvUzvglOmTPCmA9gaxD8EAcjlLOSpkVEfiYSH8BHUSz1uW3PxGK8pffKJwDW09JIiXJA1SKneNMGEiPnnTHnkzNlu0amcZw9UXurh8DeIeL" } :content_type application/json :no_cache :rerender :save variants -%} {%- comment -%} {{${first_name}}} {%- endcomment -%}{% if- {{variants.variant_text}} == blank or {{variants.variant_text}} == null -%}
PASTE YOUR HUMAN CONTROL HERE
{%- else -%}
{{variants.variant_text}}
{%- endif -%}

Note the placement of the {{${first_name}}} tag between the comment tags.

If you require multiple personalization tags, you can simply add them between the {%- comment -%} and {%- endcomment -%} tag with a space between them. A bit like this:

{%- comment -%} {{${first_name}}} {{${last_name}}}{%- endcomment -%}

If your personalization tag uses Liquid Filters to modify the output then these need to be assigned to a new variable which will be used in the Phrasee variant.

For example, if you were capitalizing first_name with {{${first_name} | capitalize}} then you would first assign this to a new variable before calling the Phrasee Content block :

{%- assign capitalizedFirstName = {{${first_name} | capitalize}} -%}
{%- connected_content https://realtime.phrasee.co/live/single_variant?campaign_id=PhAK33xPer1m3nT1d4d0cUM3NtAt1oN&delivery_id={{campaign.${message_api_id}}}&recipient_id={{${user_id}}} :method get :headers { "Authorization": "Bearer PhaKetOKen1B28LFJkDejbI5URTypk5tO1PxSZ3AqI9p1wCJ3GcpNmq6SVwZfUJUUMKEFyv6J9rKvRgEvp30HYSfkJuwGdhvUzvglOmTPCmA9gaxD8EAcjlLOSpkVEfiYSH8BHUSz1uW3PxGK8pffKJwDW09JIiXJA1SKneNMGEiPnnTHnkzNlu0amcZw9UXurh8DeIeL" } :content_type application/json :no_cache :rerender :save variants -%}{%- comment -%} {{capitalizedFirstName}} {%- endcomment -%}{%- if {{variants.variant_text}} == blank or {{variants.variant_text}} == null -%}
PASTE YOUR HUMAN CONTROL HERE
{%- else -%}
{{variants.variant_text}}
{%- endif -%}

Give it a test

Once you've added your code snippets properly to Braze and activated your experiment in Phrasee, you should be able to preview the email and see your subject lines populating dynamically.

After you've set all of this up for the first time, it's a good idea to save your code snippets somewhere safe so you can simply reuse them in the future by swapping out the experiment ID.

Preparing for deployment

Once you've verified your code snippets and personalization tags are functioning properly, you've completed your minimum email setup. You can now deploy your emails via your preferred trigger method if you're deploying triggered message experiments.

If you're sending broadcast message experiments, please proceed to the broadcast message experiment rate limiting article to learn about an additional setting you'll need to use.

When deploying to a preconfigured Segment for both triggered and broadcast messages with dynamic optimization, ensure your segment has Analytics Tracking turned ON as in the example below:

Just like that, you're as Brazed as short ribs on grandma's dinner table.

Did this answer your question?