Question

Issue triggering Placed Order event from squarespace

  • 23 June 2022
  • 7 replies
  • 39 views

Badge

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 


7 replies

Userlevel 7
Badge +55

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.

 

Badge

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(['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

Badge

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(['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

Userlevel 7
Badge +55

Hi @digibblossom,

Thanks for your reply.

Can you try adding a unique timestamp to each event?

Let us know how it goes.

Badge

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 || [];
    _learnq.push(['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

Userlevel 7
Badge +55

Hi @digibblossom,

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

Thanks for being a community member.

Badge

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

Reply