Question

Klaviyo Flow evaluating price as string instead of number? Broken?


Badge

We’ve created a simple test flow, when someone views a product, if the product is over $1.00 to send an email to mytest@email.com. The problem is the the “price” is being passed to Klaviyo with the currency symbol ($) in it.

So instead of 75.49, it is passing $75.49. Therefore, the price is no longer a number but in fact a string and therefore Klaviyo flow cannot evaluate if the price is greater than 1 or not, because it is effectively evaluating if letters > 1 (which is always false).

How can we fix this, please?


2 replies

Badge

I think it’s related to the theme > templates > product.liquid theme file, specifically the two colorized parts below. I think the fix is just to change:

Price: {{ product.price|money|json }},

To:

Price: {{ product.price|money_without_currency|json }},

If any minds smarter than my own could advise if that is correct it would be greatly appreciated!

=======

{% if settings.newsletter_form_type == 'klaviyo' %}
<script type="text/javascript" defer="defer">
  var _learnq = _learnq || [];

  var item = {
    Name: {{ product.title|json }},
    ProductID: {{ product.id|json }},
    Categories: {{ product.collections|map:'title'|json }},
    ImageURL: "https:{{ product.featured_image.src|img_url:'grande' }}",
    URL: "{{ shop.secure_url }}{{ product.url }}",
    Brand: {{ product.vendor|json }},
    Price: {{ product.price|money|json }},
    CompareAtPrice: {{ product.compare_at_price_max|money|json }}
  };

  _learnq.push(['track', 'Viewed Product', item]);
  _learnq.push(['trackViewedItem', {
    Title: item.Name,
    ItemId: item.ProductID,
    Categories: item.Categories,
    ImageUrl: item.ImageURL,
    Url: item.URL,
    Metadata: {
      Brand: item.Brand,
      Price: item.Price,
      CompareAtPrice: item.CompareAtPrice

    }
  }]);
</script>
<!-- for klaviyo added to cart -->
<script type="text/javascript">
  var _learnq = _learnq || [];
  document.getElementById("AddToCart").addEventListener('click',function (){
      _learnq.push(['track', 'Added to Cart', item]);
  });
</script>
{% endif %}

Userlevel 6
Badge +37

Hi there @cookwarecanucks,

Welcome to the Community!

If you look at the event payload for your add to cart or product, you'll see that the Price value should include a currency symbol.
What this means is that the Price value comes in as a string data type. A string/text data type cannot have numerical properties, such as the ability to filter the value as being greater than or less than a number. 
 
The root cause of this is that you need to change the way this data is being passed into Klaviyo so that it comes into Klaviyo as a numerical value. The Added to Cart snippet actually refers to the "item" variable which is defined in the Viewed Product snippet. Therefore, you need to update the Viewed Product snippet so that the Price value is a number and not a string/text. 
 
Please update the Price variable within the Viewed Product snippet to:

Price: {{ product.price|divided_by:100.0|json }}

?name=image.png
 
Once you update the Viewed Product snippet, then you should begin to see both the Viewed Product events and Added to Cart events being passed into Klaviyo with a numerical Price value going forward. That will enable you to filter/split the Flow by the numerical value of the event. 

 

Let me know if that helped,

Alex

Reply