Skip to main content
All CollectionsBraze
Braze - Dynamic Optimisation - Querying Variants by Subscriber
Braze - Dynamic Optimisation - Querying Variants by Subscriber

Using Braze's Query Builder you can determine which subscriber received which variant in a Jacquard experiment

Updated over a week ago

There are two principal steps to ensuring you can access subscriber-level variant assignment information:

  1. Ensure Braze records your Jacquard variant against each send record with a small Jacquard code snippet modification

  2. Properly querying the send records using Braze's Query Builder

Code snippet modification

Thanks to the easy-to-modify Connected Content code snippet Jacquard employs to call variants in from our real-time endpoint, we can make a simple change to the code snippet used to call the variants.

This change will instruct Braze to record the variant ID and variant called for each subscriber against the send record. We can then use other Braze fields in a query to call that record and join it with others.

The code snippet you start with for this exercise may vary slightly based on your use case and the type of testing you're conducting with Jacquard, but the structure will look very similar to the following example:

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

To instruct Braze to record the variant_id and variant_text against the send record we simply need to add the following two lines of code to the end of code snippet:

{% message_extras :key sl_id :value {{variants.variant_id}} %}
{% message_extras :key sl_text :value {{variants.variant_text}} %}

When that's done, your code snippet will look something like the following:

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

{% message_extras :key sl_id :value {{variants.variant_id}} %}

{% message_extras :key sl_text :value {{variants.variant_text}} %}

With those lines of code added, you can deploy your Braze messages using the same Jacquard sending methods you normally do.

Querying your data

After your send has deployed from Braze and some engagement data has rolled in, you can query your send in Braze's Query Builder.

You'll want to start with the following query:

SELECT  sends.USER_ID, sends.DISPATCH_ID, sends.MESSAGE_EXTRAS, count(opens.ID) as "OPENS",count(clicks.ID) as "CLICKS",count(unsub.ID) as "UNSUBSCRIBE"
FROM USERS_MESSAGES_EMAIL_SEND_SHARED sends
LEFT JOIN USERS_MESSAGES_EMAIL_OPEN_SHARED opens
ON opens.USER_ID = sends.USER_ID
AND opens.DISPATCH_ID = sends.DISPATCH_ID
LEFT JOIN USERS_MESSAGES_EMAIL_CLICK_SHARED clicks
ON clicks.USER_ID = sends.USER_ID
AND clicks.DISPATCH_ID = sends.DISPATCH_ID
LEFT JOIN USERS_MESSAGES_EMAIL_UNSUBSCRIBE_SHARED unsub
ON unsub.USER_ID = sends.USER_ID
AND unsub.DISPATCH_ID = sends.DISPATCH_ID
WHERE sends.CAMPAIGN_API_ID = '<Campaign_API_Identifier>' GROUP BY sends.USER_ID, sends.DISPATCH_ID, sends.MESSAGE_EXTRAS

Then, the only thing you'll need to do is locate your campaign's Campaign API Identifier.

You can find this by clicking on the name of your deployed campaign in the Messages area of Braze.

This will take you to your campaign's details page.

Scroll down until you see the API Identifier heading.

Just below that, you'll see a field labelled Campaign API Identifier. The string that immediately follows in what you should paste over <Campaign_API_Identifier> in the query above.

Once all of that is complete, you can run your query in Query Builder to retrieve the data you seek and export it from there for your external use.

You can find Query Builder under Analytics > Query Builder.

In the Query Builder area, click Create SQL Query > SQL Editor.

Paste your query with your Campaign API Identifier in place into the text box. Then, click Run Query.

From here, you can export your results via CSV using the teal Export button.

Once you've confirmed your query works properly, you can name it something unique so you can find it again and reuse it in the future for subsequent sends.

The basic query provided above will pull USER_ID, DISPATCH_ID, VARIANT_ID, VARIANT_TEXT, OPENS, CLICKS, and UNSUBSCRIBES. If you'd like to include any additional fields in the query (e.g. conversions), amend and expand the basic query using the Query Builder tools on the right.

For more information on using Query Builder and the credits required, please see Braze's documentation.

Did this answer your question?