Skip to main content
All CollectionsBrazeBraze - Dynamic Optimisation General Articles
Braze - Dynamic Optimisation - Content Blocks
Braze - Dynamic Optimisation - Content Blocks

Leveraging a reusable Content Block in tandem with Jacquard code snippets

Updated over 5 months ago

Code snippets updated to include liquid whitespace controls 9 April 2024.

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

Arguably the most important piece of the Braze Dynamic Optimisation integration 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 optimise your language in real time using Jacquard's Dynamic Optimisation.

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:

  • Jacquard 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 Jacquard:

{%- 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:

  • Jacquard 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:

Personalisation

If your Jacquard language contains personalisation 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 personalisation tags within the comment tags, Braze will not process them properly and 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 personalisation 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 personalisation 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 personalisation tag uses Liquid Filters to modify the output then these need to be assigned to a new variable which will be used in the Jacquard variant.

For example, if you were capitalising first_name with {{${first_name} | capitalize}} then you would first assign this to a new variable before calling the Jacquard 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 Jacquard 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 Jacquard, 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 personalisation 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 Optimisation, ensure your segment has Analytics Tracking turned ON as in the example below:

Did this answer your question?