All Collections
Braze
Braze - Dynamic optimization - Content Blocks
Braze - Dynamic optimization - Content Blocks

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. These will be stored inside a Content Block for ease of use.

The tl;dr version is we've created code snippets that work 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 Content Block

You'll need to paste the following Connected Content snippet into a Content Block:

{% connected_content https://realtime.phrasee.co/live/single_variant?campaign_id={{phraseeExperimentId}}&delivery_id={{campaign.${dispatch_id}}}&recipient_id={{${user_id}}} :method get :headers { "Authorization": "Bearer <token>" } :content_type application/json :no_cache :rerender :save variants %}

You'll notice there is a critical piece of data in the snippet:

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

Your token should be accessible for the admin(s) of your account, via the Admin > Settings menu. If you're not sure where to find your token, we've got an article for that.

Make sure you give the Content Block a sensible name for easy location when using in your messages. Here is an example:

The code snippets

Now, we shift to your message setup.

Here, 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:

{%- assign phraseeExperimentId = '<campaign_id>' -%}{{content_blocks.${phraseeContent}}}{%- comment -%}{%- endcomment -%}{%- if {{variants.variant_text}} == blank or {{variants.variant_text}} == null -%}
PASTE YOUR HUMAN CONTROL HERE
{%- else -%}
{{variants.variant_text}}
{%- endif -%}

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

{%- assign phraseeExperimentId = '<campaign_id>' -%}{{content_blocks.${phraseeContent}}}{%- comment -%}{%- endcomment -%}<img src="{{variants.statistics_url}}" width="1px" height="1px">

Generally, we recommend pasting the snippet for the HTML body just below where the preheader renders in your email.

You'll also need another critical piece of data for both of these snippets:

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

If you're not sure where to find your experiment ID, we've got an article for that, too!

Below is an example of what the code snippet for the Subject field might look like with an experiment ID 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:

{%- assign phraseeExperimentId = 'PhAK33xPer1m3nT1d4d0cUM3NtAt1oN' -%}{{content_blocks.${phraseeContent}}}{%- 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}} -%}
{%- assign phraseeExperimentId = 'PhAK33xPer1m3nT1d4d0cUM3NtAt1oN' -%}{{content_blocks.${phraseeContent}}}{%- comment -%} {{capitalizedFirstName}} {%- endcomment -%}{%- if {{variants.variant_text}} == blank or {{variants.variant_text}} == null -%}
PASTE YOUR HUMAN CONTROL HERE
{%- else -%}
{{variants.variant_text}}
{%- endif -%}

The Phrasee variants will then contain {{capitalizedFirstName}} as the replacer tag.

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?