Skip to main content
All CollectionsBraze
Braze - Dynamic Optimisation - Code Snippets
Braze - Dynamic Optimisation - Code Snippets

Learn how to properly implement the Jacquard code snippets

Updated over a week 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.

The short 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 optimise your language in real time using Jacquard's Dynamic Optimisation.

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

{%- 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 personalisation variables, which are unsupported in the default function, the approach has now been changed. Updated 4 January 2024.

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:

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

  • Jacquard 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 Jacquard Customer Success representative.

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

{%- 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 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}} -%}
{%- 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 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?