Skip to main content
Active Contributor I
January 12, 2024
Solved

How to implement javascript in Klaviyo email

  • January 12, 2024
  • 1 reply
  • 656 views

I want to implement a javascript calculation in my Klaviyo email.

The calculation- If you are given a price x and you are asked that if this price x was invested in gold 5 years ago, what would be it's value today.

The price x here will be dynamic variable of the cart value.
The code is pretty simple, I managed to do it with ChatGPT and it worked.

 

But how can I implement this in Klaviyo?
Javascript is not supported, is it possible to host the JS code online or something else?

    This topic has been closed for replies.
    Best answer by bluesnapper

    Hi @rohan12334 

    As you say, no JS in an email.

    If it’s a simple calculation, you may be able to do this in Klaviyo using filter variables and include that in your email. More info here: https://help.klaviyo.com/hc/en-us/articles/360058466052

    For example, if the formula is something like Value Today=Value in their cart x (1+annual growth rate) ^ raised to the power of the Number of Years. You can calculate the static value I’ve underlined, then pull in the variable part, which is the value of their cart, and use variable filters to calculate Value Today.

    So in your abandoned checkout email:

    If you had invested ${{ event|lookup:'$value'}} in gold 5 years ago, that investment would now be worth ${{ event|lookup:'$value'|multiply:1.3 }}

    This is for a Shopify event variable and where 1.3 is just a random number I’ve used in my example but you’d use the growth rate and 5 years to get your multiplier.

    I’m not sure if this is exactly what you’re after - it doesn’t consider that they could purchase more gold for their money 5 years ago (assumption!)…but maybe a starting point for you.

    Regards

    Andy 

     

    1 reply

    bluesnapper
    Partner
    Champion & Partner
    January 12, 2024

    Hi @rohan12334 

    As you say, no JS in an email.

    If it’s a simple calculation, you may be able to do this in Klaviyo using filter variables and include that in your email. More info here: https://help.klaviyo.com/hc/en-us/articles/360058466052

    For example, if the formula is something like Value Today=Value in their cart x (1+annual growth rate) ^ raised to the power of the Number of Years. You can calculate the static value I’ve underlined, then pull in the variable part, which is the value of their cart, and use variable filters to calculate Value Today.

    So in your abandoned checkout email:

    If you had invested ${{ event|lookup:'$value'}} in gold 5 years ago, that investment would now be worth ${{ event|lookup:'$value'|multiply:1.3 }}

    This is for a Shopify event variable and where 1.3 is just a random number I’ve used in my example but you’d use the growth rate and 5 years to get your multiplier.

    I’m not sure if this is exactly what you’re after - it doesn’t consider that they could purchase more gold for their money 5 years ago (assumption!)…but maybe a starting point for you.

    Regards

    Andy 

     

    https://bluesnapper.com - Klaviyo Champion '24 & Partner