Skip to main content

Hi, 

I am trying to connect my squarespace website to Kaviyo and trigger a flow when a customer complete a purchase. I have been trying to add code to the footer of the oder details page following the Kaviyo API guide. However I still couldn’t get it to work. I have a few questions:

  1. Do we need to make a call to /identity and then /track? 
  2. I tried to do something like :

<script type="text/javascript">

var xhr = new XMLHttpRequest();

 

xhr.open("POST", "https://a.klaviyo.com/api/identify", true);

xhr.onreadystatechange = function(){

if(xhr.readyState === 4 && xhr.status === 200) {

var x = new XMLHttpRequest(); x.open("POST", "https://a.klaviyo.com/api/track",false); x.send(JSON.stringify({

"token": "xxxxx",

"event": "Placed Order",

"customer_properties": {

"$email": "ttesting" ,

} }));

}

}

xhr.send(JSON.stringify({

"token": "xxxxx",

"properties": {

"$email": "ttesting"

}

}));

</script>

 

But they didnt work. So I tried the frontend call method and did  something like:


This time it somehow works, and there is a custom matrix called “Placed Order” (different than the default one) shows up. So I was trying to use this custom  “Placed Order” to trigger a flow. However this call only works once. I tried to place a several test orders and this matrix is not triggered:

I could only trigger this once

May I get some help please? Thanks a lot.

 

Many thanks,

Meiya 

Hi @digibblossom,

Thanks for sharing this question with us.

You can use just the Track API in this case since you are just looking to track profile activity i.e. a Placed Order event.

Can you try adding an event id to each request in the payload? An $event_id is a unique identifier for an event for example an order ID. If there is no $event_id, we’ll assign the timestamp and if the timestamp data from event-to-event is exactly the same, Klaviyo will interpret it as a duplicate and not record the second, third, fourth etc. events. So either adding a $event_id to each event or a timestamp should resolve this.

I hope that’s helpful.

 


Hi @Dov , may I know if I should do something like :

<script
  async type="text/javascript"
  src="//static.klaviyo.com/onsite/js/klaviyo.js?company_id=xxx"
></script>

<script>
  var _learnq = _learnq || ];

  
  _learnq.push(q'track', 'Placed Order', {
      "token": "xxx",
    "customer_properties": {
      "$email": '{{customerEmailAddress}}'
    },
      "properties": {
        "$event_id": '{{orderId}}' 
      }
 }]);
</script>

 

I added the event_id but there is nothing triggered in analytics

 

Warm regards,

Meiya


Hi @digibblossom,

Thanks for sharing this question with us.

You can use just the Track API in this case since you are just looking to track profile activity i.e. a Placed Order event.

Can you try adding an event id to each request in the payload? An $event_id is a unique identifier for an event for example an order ID. If there is no $event_id, we’ll assign the timestamp and if the timestamp data from event-to-event is exactly the same, Klaviyo will interpret it as a duplicate and not record the second, third, fourth etc. events. So either adding a $event_id to each event or a timestamp should resolve this.

I hope that’s helpful.

 

Hi @Dov , may I know if I should do something like :

<script
  async type="text/javascript"
  src="//static.klaviyo.com/onsite/js/klaviyo.js?company_id=xxx"
></script>

<script>
  var _learnq = _learnq || r];

  
  _learnq.push(r'track', 'Placed Order', {
      "token": "xxx",
    "customer_properties": {
      "$email": '{{customerEmailAddress}}'
    },
      "properties": {
        "$event_id": '{{orderId}}' 
      }
 }]);
</script>

 

I added the event_id but there is nothing triggered in analytics

 

Warm regards,

Meiya


Hi @digibblossom,

Thanks for your reply.

Can you try adding a unique timestamp to each event?

Let us know how it goes.


Hi @digibblossom,

Thanks for your reply.

Can you try adding a unique timestamp to each event?

Let us know how it goes.

Hi @Dov , 

Hope you are doing well. I tried using the following code: 

 

<script>
    var _learnq = _learnq || a];
    _learnq.push(a'identify', {
    '$email': {customerEmailAddress}
  }]);
  _learnq.push( 'track', 'Placed An Order', {
    'test' : true

  }]);
</script>

I can see in the matrix list there is a new matrix called 'Placed An Order', however 0 event is triggered. I am really confused and struggled. Please help.

 

Warm regards,

Meiya


Hi @digibblossom,

For further technical assistance, I recommend reaching out to one of our wonderful partners.

Thanks for being a community member.


Hi @digibblossom, did you get it working in the end please?
Same issue here


Reply