Overview
Using Smarty and contact attributes, you can randomly add contacts to a group when a message sends. You can then perform actions such as filtering stats, building audiences, and adding personalization based on a contact's group assignment.
This is useful for testing multiple messages over time to a static group of contacts selected at random. For example, you can create a welcome series and test a consistent promotion (percentage vs dollar discount) to each group across several messages within the series.
Our example
Upon message send, the following code example will:
- Randomly populate a contact attribute named
group
with a value of A or B for each contact. - Render HTML message content based on the
group
value for each contact. - Create a stats filter send tag named with the
group
value.
Use the tabs below to switch between the message code and the stats filter results.
-
{if $contact.group != 'A' && $contact.group != 'B'} {$data.random="{math equation='rand(min, max)' min=1 max=2}"} {if $data.random == 1} {$contact.group = 'A'} {$utils->updateContact(['group'=>$contact.group])} {else} {$contact.group = 'B'} {$utils->updateContact(['group'=>$contact.group])} {/if} {/if} {if $contact.group == 'A'} {$utils->addSendTag($contact.group)} <!--HTML Content--> {/if} {if $contact.group == 'B'} {$utils->addSendTag($contact.group)} <!--HTML Content--> {/if}
Add a contact to a group
1. Create a new contact attribute and name it group
.
2. Randomly populate the group attribute for each contact with a value of A or B when the message sends using the following Smarty:
{if $contact.group != 'A' && $contact.group != 'B'} {$data.random="{math equation='rand(min, max)' min=1 max=2}"} {if $data.random == 1} {$contact.group = 'A'} {$utils->updateContact(['group'=>$contact.group])} {else} {$contact.group = 'B'} {$utils->updateContact(['group'=>$contact.group])} {/if} {/if}
3. When the message sends, the Smarty code above will check to see if the contact has a value of A or B for the group attribute. If not, it will randomly select either A or B and update the contact with that value.
Use stats filters with groups
Append the Smarty code above with the additional code below to create a stats filter send tag named with the group value for each contact.
{if $contact.group == 'A'} {$utils->addSendTag($contact.group)} <!--HTML Content--> {/if} {if $contact.group == 'B'} {$utils->addSendTag($contact.group)} <!--HTML Content--> {/if}
By placing your message HTML within the {if} statement for each group, you can send unique content for group A and group B. To keep code clean and manageable, you can also use HTML content includes to render the code within the {if} statements.
View the message stats
After sending the message, you can filter the message stats using stats filters.
1. On the Message Performance page, scroll down to the Stats Filters section and add each of the stats filter send tags that were created by the Smarty code. Our example created the tags A and B.
The image below shows the results of our message performance with the stats filters applied.
Compare message stats across multiple messages
Using this strategy, you can compare message stats for multiple messages to see which group is performing best. For example, you can create a welcome series and compare how content for group A performs against group B. You can then make content decisions based on the performance.
This works similar to creating an experiment with a split test strategy; however, the split group in experiments is unique for each message. The technique outlined in this article allows you to maintain a static group assignment for contacts over time.
Segmentation and personalization using groups
Now that you have contacts assigned to each group, you can communicate with them according to their group assignment.
For example, Group A could be receiving a specific promotion based on a percentage, while Group B is receiving a promotion based on a specific dollar amount. You can segment and personalize based on these group assignments, analyze stats, and make decisions based on performance.
Audience configuration based on groups
Below is an example of an audience configuration that targets contacts in group A that have received the first welcome message in a series.
Personalization based on random groups
Below is an example of Smarty that will render HTML based on a contact's group assignment.
{if $contact.group == 'A'} <!--HTML Content--> {elseif $contact.group == 'B'} <!--HTML Content--> {/if}
Comments
0 comments
Please sign in to leave a comment.