Forum Discussion

SofiaZ's avatar
SofiaZ
Active Member II
2 years ago

Randomize or changing copy each time customer enters the same canvas

Hi guys! 
I'm trying to build a canvas with a single message step (email), in which I want the subject line to be different each time a recipient becomes re-eligible to enter and receive the email. I'm thinking of altering between 10 different subject lines, so as not to tire the recipients. 

Do you have any recommendations on how I could build the canvas/liquid to do this without having to manually edit it when it's live? Is there a way to line up a que of different copy and have the recipient see the next one in the que each time the enter the canvas/step?

  • Hey Sofia, I am trying to do something similar and the best solution I have found so far is leveraging the 'Catalogs' and 'Sections' feature that Braze offers.

    How I set it up:

    - Uploaded a list of subject lines as catalog (Unfortunately, it doesn't allow for most punctuation or emojis so you have to keep the subject lines very simple)

    - Create a 'Selections' and turn on random sort order

    - Fill in the content below and add this into the subject line field:
    {% catalog_selection_items INSERTNAMEOFCATALOG INSERTNAMEOFSELECTIONS%}
    {{items[0].INSERTCATALOGFIELDNAME}}

    Using this method allowed me to randomize the subject line that was pulled in (although there is still a chance it will pull in the same one in a row)

    Hope this helps!

     

     

     

    • SofiaZ's avatar
      SofiaZ
      Active Member II

      Hi Sydney, thank you for a great solution. Wow, that's a creative way to use Catalogs!

  • Max's avatar
    Max
    Specialist

    Hey SofiaZ 🙂 I would suggest to use Liquid as well, but instead of storage the 10 different text versions in an if function, you can create a content block with an JSON object and use a content block ðŸ˜‰. Let me explain how to do it:

    First we have to create a JSON object like:

    {
       "subjectline":{
          "0":{
             "text":"This is a great subject line"
          },
          "1":{
             "text":"This is another great subject line"
          }
       }
    }

    Continue this schema with your 10 different versions. Important: You have to start with 0 and please format the JSON object with a formatter.

    Next, we create and save a content block and add some liquid, like this:

    {% capture subjectElements %}
    
    {
       "subjectline":{
          "0":{
             "text":"This is a great subject line"
          },
          "1":{
             "text":"This is another great subject line"
          }
       }
    }
    
    {% endcapture %}
    {% assign object=subjectElements | json_parse %}

    Now, we just have to add the following liquid in our communication to create a random number and select a random copy. The liquid below will generate a random number between 0-9 :

    {% assign timeinsec = 'now' | date: "%s" %}
    {% assign randomNumber = timeinsec | modulo: 10 %}

    Now, we have to use this number to generate our random subject line with:

    {{content_blocks.${random_text}}}
    {% assign timeinsec = 'now' | date: "%s" %}
    {% assign randomNumber = timeinsec | modulo: 10 | append: randomNumber %}
    {{object.subjectline[randomNumber].text}}

    Short explanation:

    1. We add the content block, which we created 
    2. We create a variable to define the current time in seconds
    3. We create a random number based on the time variable and modulo it by 10. Furthermore, we also add the string filter 'append' to change the variable from an integer to a string.
    4. We use our object with the random number to display the random text

    What is the benefit behind this solution?

    1. The content in your communication is shorter and more clearly arranged
    2. You can always make changes easily in the content block

    Let me know if this worked for you, or you have any questions!

    Cheers!

    • DavidO's avatar
      DavidO
      Strategist II

      Max this is super clever. I'm off to go try this out and see what can be done. Thanks!

  • jakedavis's avatar
    jakedavis
    Active Member II

    Hey Sofia,

    You could use if/then logic in Liquid to look at a custom attribute and tailor the subject line (or any content) based on that custom attribute. Let me explain: 

    Let's create a custom attribute called "WelcomeEmailContentVersion" and set the type as a number. When someone enters this canvas for the first time that value will be null, so you'd need copy for when that value is null, 1, 2, etc. 

    Create your email, and use Liquid to build out your list of subject lines. There are a few ways you could dev the liquid snippet, if/then logic, or a case statement event, but could look something like this:

     

    {% if custom_attribute.${WelcomeEmailContentVersion} == '1' %}
    Subject Line 1
    {% elsif custom_attribute.${WelcomeEmailContentVersion} == '2' %}
    Subject Line 2
    {% elsif custom_attribute.${WelcomeEmailContentVersion} == '3' %}
    And on and on
    {% else %}
    Subject Line for the null value on first entry
    {% endif %}

     

    Immediately following your email step, add the User Update step and configure it like this:

    1. Attribute Name: WelcomeEmailContentVersion
    2. Action: Increment By
    3. Increment By: 1

    So now the next time a subscriber enters this canvas, the custom attribute WelcomeEmailContentVersion will be the previous value plus 1.

    This wouldn't make it random, but it would keep the user from receiving the same SL over and over again. The ELSE subject line would be what they receive on the first entry and then any entry beyond the 10th if you configure the Liquid to have 10 subject lines.

    Similarly, you could pair this solution with a Catalog of subject lines to have a long list of subject lines in one central location that's easy to update, and keep then Liquid logic pretty simple to just look up a SL based on what your incrementing custom attribute is. You'd keep using the incrementing User Update step in the Canvas but you wouldn't have to update the email HTML and Liquid if you want to update the subject lines. 

    Hope that helps! 

  • DavidO's avatar
    DavidO
    Strategist II

    Hi SofiaZ

    I would use a content block of Liquid as jakedavis suggested but rather than a custom attribute you could place a random number generator at the start so that every time the block is run it chooses a random number and lines of text.

     

     

    {% assign randomNumber = "now" | date: "%N" | modulo: 10 %}
    {% if randomNumber == '0' %}
    Subject Line 1
    {% elsif randomNumber == '1' %}
    Subject Line 2
    {% elsif randomNumber == '2' %}
    And on and on
    {% else %}
    Subject Line for the null value on first entry
    {% endif %}

     

     

    Changing the 'modulo' number will change the range of random numbers. In this case it is 0 - 10. If you change it to module: 25, it will select between 0 - 25. 

    Technical logic:
    randomNumber is taking the exact time of day 'now' and converting it to %N which is 'Fractional seconds digits, default is 9 digits (nanosecond)', which updates all the time.

    It comes back with numbers such as:
    928616331
    201621187
    187114708

    This number is then divided by the value of modulo and only the remainder of that equation is returned which becomes your new randomNumber.
    modulo – Liquid template language (shopify.github.io)

    Note: This random number generator does not remember what was picked last time so it is possible that it will produce the same randomNumber twice in a row. Otherwise, it would need to be more complex and include an array of previously selected numbers.

    😊

    • SofiaZ's avatar
      SofiaZ
      Active Member II

      Thank you so much David, and also for explaining how Modulo works. I've seen peopel reference it often but can never understand how it works. 

  • DanyWillis's avatar
    DanyWillis
    Practitioner III

    Hello, I actually built something very similar to what your talking about for our 2000 recipes we offer. I'd recommend you getting grasps with Liquid and looking into building a random number generator and assigning variables to each out outcome.

  • Stuart's avatar
    Stuart
    Practitioner III

    Hey SofiaZ, did you still help with this? I can see all answers cover 'random' generation and not 'random'+not receive the same SL consecutively.

    Using Liquid and connected content (in the subject line message), I would record the SL that the user receives as a Custom Attribute (e.g. lastSubjectLine), so when a user re-enters the same step, the logic would say: deliver a random SL but exclude the lastSubjectLine as an option to choose from.