Forum Discussion

Marc's avatar
Marc
Active Member
2 years ago

Liquid using time of open conditions in email?

Can we use liquid in an email to display certain content based on time of email open? So, if a user opens an email during morning hours, have it serve X content. And if a user opens the same email during evening hours, have it serve Y content.

I believe there's use cases for time of send, but I'm looking specifically for time of email open. 

Thanks!

  • Hi Marc 

    Liquid is evaluated at the time an email is sent, so any time-based calculations are evaluated when the email is triggered and already rendered before the email is delivered. Even if you recorded the email open click, the email is already rendered in their inbox, so I'm struggling to see how it could be updated in real-time but I would love to know if others have workarounds, it's a great question.

    For reference, some liquid that can determine the time of day would look something like the following:

     

    {% assign timeOfDay = 'now' | date: '%H' | plus: 0 %}
    
    {% if timeOfDay >= 0 and timeOfDay < 12 %}
      Good morning!
    {% else %}
      Good evening!
    {% endif %}

     

    This assigns the current time 'now' to a variable, only keeping the current two-digit hour (%H), for example 02. Since this returns a string, we plus a 0 to that string. which turns the 02 into an integer that we can work with.

    The if / else is then determining morning and evening based on that hour.

    I hope that helps😊

2 Replies

  • DavidO's avatar
    DavidO
    Strategist II

    Hi Marc 

    Liquid is evaluated at the time an email is sent, so any time-based calculations are evaluated when the email is triggered and already rendered before the email is delivered. Even if you recorded the email open click, the email is already rendered in their inbox, so I'm struggling to see how it could be updated in real-time but I would love to know if others have workarounds, it's a great question.

    For reference, some liquid that can determine the time of day would look something like the following:

     

    {% assign timeOfDay = 'now' | date: '%H' | plus: 0 %}
    
    {% if timeOfDay >= 0 and timeOfDay < 12 %}
      Good morning!
    {% else %}
      Good evening!
    {% endif %}

     

    This assigns the current time 'now' to a variable, only keeping the current two-digit hour (%H), for example 02. Since this returns a string, we plus a 0 to that string. which turns the 02 into an integer that we can work with.

    The if / else is then determining morning and evening based on that hour.

    I hope that helps😊

  • Marc's avatar
    Marc
    Active Member

    Hey David. Thanks for the response on this. Originally we thought that Liquid was maybe evaluated up until the time of open, but good to know it is evaluated at the time the email is sent. Appreciate the help!