Solved

Klaviyo dropping events that are sent too close to each other

  • 16 September 2021
  • 4 replies
  • 557 views

Badge +2

Hello, I am working on integrating Klaviyo into an existing web page. I am having an issue where if I send events to Klaviyo, many of them don’t appear in Klaviyo. the post requests are all returning status code 200, so I assume that Klaviyo is recieving all of them. If I add a delay of 1 second between each request sent to Klaviyo, none of them get dropped. This seems to fix the issue, but it feels like a band-aid fix that’s just going to cause problems down the line, so I’d like to figure out why Klaviyo doesn’t seem to like multiple requests in quick succession. Usually I’m sending a placed order event, followed by anywhere from 2-12 ordered product events.

 

Here is the code I’m using to send the requests (written in vbscript):

Function SendJson(jsonString)
        Try
            Dim bytes = System.Text.Encoding.UTF8.GetBytes(jsonString)
            Dim request = WebRequest.Create("https://a.klaviyo.com/api/track")
            request.Method = "POST"
            request.ContentType = "application/json"
            request.ContentLength = bytes.Length
            Dim stream = request.GetRequestStream()
            stream.Write(bytes, 0, bytes.Length)
            stream.Close()
            Dim response = CType(request.GetResponse(), HttpWebResponse)

            If response.StatusCode <> 200 Then
                Return "Error: post request returned status code " + response.StatusCode + " for request:" + vbNewLine + jsonString
            End If
            Return "Request successful for request:" + vbNewLine + jsonString
        Catch exception As Exception
            Return "Error: " + exception.Message + "for " + jsonString + vbNewLine + exception.StackTrace
        End Try
    End Function

icon

Best answer by David To 17 September 2021, 17:49

View original

4 replies

Userlevel 7
Badge +60

Hello @Jason,

Thanks for sharing your question with the Klaviyo Community!

Klaviyo’s Track api endpoint is actually very high throughput and therefore wouldn’t be rate-limited easily. When you mentioned triggering these metrics multiple times in quick succession, do these events happen to have the exact same event name and timestamps? If so then this is actually expected behavior. When multiple events have the same exact event name and timestamp, then they’re treated as duplicate events and ignored unless these events have a unique $event_id to distinguishing them as separate events. 

I’ve also attached some helpful Community posts below which touch upon this similar subject:

I hope this helps!

David

Badge +2

Figured out what the issue was. I had a unique event id for each request, but I was putting it in the top level of the JSON string instead of nesting it in properties. Changed that, and everything’s working perfectly.

Badge +1

Figured out what the issue was. I had a unique event id for each request, but I was putting it in the top level of the JSON string instead of nesting it in properties. Changed that, and everything’s working perfectly.

I have done the same nested event id in properties but still same isse

here is a json sample

{
  "token": "XXXXXX",
  "event": "gt-rec-card",
  "preview_text ": null,
  "customer_properties": {
    "toSendList": [],
    "$email": "abc@gmail.com",
    "$first_name": null,
    "$last_name": null,
    "$phone_number": null,
    "$city": null,
    "$region": null
  },
  "properties": {
    "event_id": "XXXXXX",
    "termsconditions": null,
    "instruction": null,
    "cardnum": null,
    "pinnum": null,
    "ticketone": null,
    "tickettwo": null,
    "expirydate": null,
    "senderphonenum": null,
    "thisrequired": false,
    "requiresverification": false,
    "verifiyidentity": null,
    "vouchername": "Arif Astori",
    "collection_link": "https://link/q1W8",
    "retailercontactname": null,
    "sendername": "Monica",
    "cardmessage": "Happy birthday",
    "subject": "Joe, Monica has ..!",
    "$value": 0
  }
}

Userlevel 7
Badge +60

Hey @Arif Hussain,

I took the liberty to update your comment to omit any potentially sensitive data. 

One thing I noticed in your call though, instead of using event_id, I would suggest using $event_id. As highlighted in our Track API reference Developer Guide:

A unique identifier for an event. You should send an $event_id if you have a unique identifier for each event (e.g. an order ID) in the following format: event name+timestamp+customer email/id.

If you don't specify an $event_id, it will default to the timestamp of the event.

You should also set the $event_id if you expect certain events to occur at the same point in time, which you will then want to split into multiple events. For example, if someone orders multiple items in one order, you may want to record one event for each item purchased.

Additionally, I would also suggest ensuring that the $event_id you are using is unique to the event you are passing as I previously mentioned in the How do you update the fields of historic event data that was uploaded? Community post above. For example, if you had two calls being made with matching event and $event_id, then it would be an expected behavior that the subsequent call would be dropped. 

David

 

Reply