Skip to main content
All CollectionsBrazeBraze - SMS Experiments
Braze - SMS - Setting Up a Message
Braze - SMS - Setting Up a Message

How to use code snippets in an SMS deployment

Updated over 2 months ago

With your reusable Content Block created, we can move on to the message.

You'll be using another Connected Content code snippet to reference the Content Block you created.

While the Content Block is reusable, you will need to make important changes to the code snippet in your message for each new Jacquard experiment you run.

If you're planning to save the code snippet we're about to review for reuse, ensure you remember to update each requisite piece as instructed below.

Written walkthrough

1. Paste the code snippet into the Message field

Each time you are deploy an SMS message with a unique Jacquard experiment, you'll need to paste the following code snippet into the Message field.

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

In the example below, you can see the code snippet placed properly.

2. Replace the Content Block name placeholder with your Content Block's name

You'll need to paste the name of the reusable Content Block you created earlier over the CONTENT_BLOCK_NAME placeholder. When you do, ensure you leave the open and close brackets intact.

You'll notice in our example our block is named jacquardSMS.

3. Replace the campaign ID placeholder with your experiment ID

Each Jacquard experiment has a unique experiment ID. You'll need to paste your experiment's unique ID over the <campaign_id> placeholder in the code snippet.

If you need help locating your experiment ID, see our ID documentation.

When pasting your experiment ID, ensure you leave the apostrophes surrounding the placeholder intact but remove the angle brackets, as in the example below:

4. Replace the fallback placeholder with your human control language

The code snippet has fallback logic in place in the event Braze encounters problems processing the snippet.

You'll need to replace the PASTE YOUR HUMAN CONTROL HERE placeholder text with your actual human control language from your Jacquard experiment:

5. Add in any additional required SMS content

SMS messages often require the inclusion of specific messaging for legal and compliance purposes (e.g. help, stop, and rates messaging). If this messaging was not built into your Jacquard language model, ensure you're including it in addition to your code snippet. Remember these additional pieces will also contribute to your character count.

Billable Segment Alerts

Above the Message field you may see an alert indicating your SMS message will use excess billable segments. This is a result of Braze simply counting the number of characters fin the code snippet as opposed to counting the characters in the rendered variant. Because we’re using Connected Content to pull in text from the Jacquard API, the actual character count (and thus the billable segments) will depend on the final text generated and delivered by Jacquard.

Ensure you speak with your Customer Success representative if you feel the character count of your actual variants will exceed your limit so they can liaise with our technical teams to correct it.

6. Add personalisation tags to the language code snippet (optional)

If your Jacquard language variants contain any personalisation tags, please expand the Personalisation section below for further instructions.

Personalisation

Personalisation includes anything from first name to product. It's any field Braze will need to process to plug in information unique to a user.

You'll need to add your personalisation tags to your code snippet in between the {% comment %} and {% endcomment %} tag.

If you don't include the personalisation tags within the comment tags, Braze won't process them properly, and they'll be rendered as literal text within your subject line. This would result in something like Hi, {{$first_name}} displaying for a subscriber.

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 %}
Something special just for you...
{% 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, as in:

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

If your personalisation tag uses Liquid Filters to modify the output, then these filters need to be assigned along with the tag to a new variable. It's this variable that would then appear in your Jacquard language.

For example, if you want to capitalise the first_name field with {{${first_name} | capitalize}}, then you must 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 %}
Something special just for you...
{% else %}
{{variants.variant_text}}
{% endif %}

Note how the assign capitalizedFirstName appears before the assign phraseeExperimentId and also how the newly created variable, {{capitalizedFirstName}}, now appears between the comment tags instead of the default personalisation tag.

7. Select Advanced Tracking within Link Options

In order for Jacquard to optimise your message, you must include a link for your subscribers to click on in the message. Depending on your Jacquard language model, this may be populated for you within your generated variants.

Either way, you'll need to toggle Link Shortening on and choose Advanced tracking within the Link Options section in Braze. This will ensure click data is passed back to Jacquard. Without this, Jacquard will not receive click data and will, therefore, not be able to optimise your message.

Remember, the shortened link will also contribute to your character count.

8. Test your message

Once you've added your code snippet properly and activated your experiment in Jacquard, you should be able to preview the SMS message and see your variants populating dynamically.

In addition to previews, we always recommend as a best practice to do a live deployment to a small, internal test list to ensure everything will function correctly in a live send.

CEPs often render previews differently than live sends, so it is important to test both.

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

Once you've verified your code snippet and personalisation tags (if used) are functioning properly, you've completed your minimum setup.

Continue along the article path for important instructions for deploying your experiment.


Article path

Related articles

Page last reviewed: 26 November 2024

Did this answer your question?