In this article:
Using Smarty utilities, you are able to update contact attributes and list values when a message is sent.
Use the following code to run the Smarty function. Replace attribute_key with the desired attribute to be updated and new_attribute_value with the new value.
{$utils->updateContact(['attribute_key'=>'new_attribute_value'])}
Update Contact Attributes
Subscribe Status
Update contact's subscribe status
{$utils->updateContact(['channels'=>['email'=>['subscribeStatus'=>'subscribed']]])}
The above will update the contact's email subscribeStatus attribute to "subscribed".
String Attributes
Update a String Attribute
{$utils->updateContact(['flavor'=>'chocolate'])}
The above will update the contact's flavor attribute to "chocolate".
Use external variables to update contact attribute
You can pass an external variable in your message using {$extVars.variableName}
and then add the variable data to a contact attribute of your choice:
{$utils->updateContact(['flavor'=>{$extVars.chocolate}])}
The above will update the contact's flavor attribute with data passed as external variable.
Number Attributes
Update a Number Attribute
{$utils->updateContact(['viewed'=>'3'])}
The above will update the contact's viewed attribute to "3".
Increment and Decrement Number Attributes
Increment a number
{$utils->updateContact(['total'=>['inc' => '+1']])}
The above will update a contact's total attribute by "+1".
Decrement a number
{$utils->updateContact(['viewed'=>['inc' => '-1']])}
The above will update a contact's viewed attribute by "-1".
Array Attributes
Update an Array Attribute
{$utils->updateContact(['fav_fruit'=>['banana']])}
The above will update the contact's fav_fruit array attribute with the value of "banana". Note that all existing array values will be overwritten.
{$utils->updateContact(['fav_fruit'=>['banana','apple']])}
The above will update the contact's fav_fruit array attribute with the values of "banana" and "apple". Note that all existing array values will be overwritten.
Add Values To an Array Attribute
{$utils->updateContact(['fav_fruit'=>['add' => ['orange','strawberry']]])}
The above will add the values "orange" and "strawberry" to the contact's fav_fruit array attribute. Existing values will be retained unless the max items limit is exceeded.
Remove Values From an Array Attribute
{$utils->updateContact(['fav_fruit'=>['remove' => ['orange','strawberry']]])}
The above will remove the values "orange" and "strawberry" from the contact's fav_fruit array attribute.
Update list membership
You can add or remove a contact to a specified list with the following code by replacing mylist with the name of the list to be updated and either true (on the list) or false (off the list).
{$utils->updateContact(['mylist'=>true])}
Add to a list
{$utils->updateContact(['weekly-specials'=>true])}
This will add the contact to the "weekly-specials" list.
You can add the contact to more than one list by separating the key/value pairs by a comma: ['weekly-specials'=>true,'monthly-specials'=>true]
.
Remove from a list
{$utils->updateContact(['weekly-specials'=>false])}
This will remove the contact from the "weekly-specials" list.
You can remove the contact from more than one list by separating the key/value pairs by a comma: ['weekly-specials'=>false,'monthly-specials'=>false]
.
Combining multiple update functions
You are able to combine multiple update functions into one tag.
{$utils->updateContact(['flavor'=>'vanilla','age'=>['inc' => '+1']])}
This will update the contact's flavor attribute to "vanilla" and increment the age attribute "+1".
In the next article learn about using webhooks.
Comments
0 comments
Please sign in to leave a comment.