Skip to main content
Contributor I
March 5, 2024
Solved

Metric Aggregate Endpoint - Ordered Product by Campaign

  • March 5, 2024
  • 17 replies
  • 274 views

Hello,

 

Below is my payload for https://a.klaviyo.com/api/metric-aggregates/, however I do not get the data back broken down by campaign. However the same payload works for a different metric like “Clicked Email”

{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "HnmbpY",
            "measurements": ["count","unique","sum_value"],
      "interval": "day",
      "page_size": 1000,
      "timezone": "America/New_York",
            "by": ["Campaign Name"],
              "filter": [  
                  "greater-or-equal(datetime,2024-02-01)",  
                  "less-than(datetime,2024-02-29)"
              ]
    }
    }
}

 

Below are payload results:

 

Goal is to retrieve sum_value (dollar amounts) for below metrics at campaign level for given dates.

 

Thanks,

Shikha

This topic has been closed for replies.

17 replies

Klaviyo Employee
March 5, 2024

Try using "$attributed_message” as the “by” value, since events like Ordered Product are attributed to a campaign (or flow) message based on the attribution window you have set in your account.

https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes

Contributor I
March 5, 2024

@saulblum Thank you so much!

So "$attributed_message”  works for “Ordered Product”, but it does not work for “Opened Email”. “Opened Email” works when using by: "Campaign Name"

So if I am understanding it correct, some events work with "$attributed_message”  and some work with "Campaign Name".

Do you have a list of which events work with "$attributed_message” and which work with "Campaign Name"?

I am trying to pull all three measurements for all events(metrics) at day, campaign and flow level. So I need to determine which ones need "$attributed_message” and which ones need “Campaign Name" for metric aggregate endpoint. 

Your help is greatly appreciated to migrate to new API.

 

Thanks,

Shikha

 

Klaviyo Employee
March 5, 2024

Events tied directly to specific emails — Opened Email, Clicked Email, etc. — will use Campaign Name. Events that are not tied to specific messages but which can be attributed to a message — e.g. I placed an order three days after opening a campaign email — will use the “attributed” properties.

Contributor I
March 5, 2024

Is there a full list you can share on events:

  1. tied directly to specific emails and 
  2. Events that are not tied to specific messages but which can be attributed to a message
saulblumAnswer
Klaviyo Employee
March 5, 2024
Contributor I
March 14, 2024

Hi, 

I have a follow up question:

Using below payload for Flow:

For Ordered Product metric, the sum_value returned for the above flow does not seem to match the API. What am I doing wrong here?

 

 

Klaviyo Employee
March 15, 2024

Hi, the difference is probably from how the API and the UI are treating dates.

For the API call, you are looking at all Ordered Product events on 1/1/24, and then getting the sum of those events attributed to the flow in question.

When you look at the flows report, you are looking at all flow emails sent on 1/1/24, and then getting the sum of orders attributed to the flow.

So if the flow sent me an email on 1/1/24 and I placed an order on 1/3/24, it would not be counted in the API call, but would be in the UI report.

There’s a new reporting API that will get you results that match those in the UI: https://developers.klaviyo.com/en/reference/query_flow_values

Contributor I
March 15, 2024

Thank you! This helps. 

So to be clear, the metric aggregates provides data by the date the event happened and the Reporting API provides data by the date the email is sent (via campaign or flow), Is my understanding correct? Is there any formal documentation that I can use to clear this up with my business.

Follow up question: On the reporting API, is it possible to break the data down by date when a range is given?

 

Klaviyo Employee
March 15, 2024

Correct, one is tracking when conversion events — e.g. Ordered Product — happened in a specified time frame, the other is tracking when messages were sent in a time frame, that led to conversion events.

Follow up question: On the reporting API, is it possible to break the data down by date when a range is given?

I think the flow series report will do this. Here’s a doc that was given to early testers of the reporting API: https://docs.google.com/document/d/1Ca8asJWWNiDJJODMsIrn1l40NthKDww64GwgqUGRg1s/edit

Contributor I
March 19, 2024

Hi There,

Would you please let me know what am I doing wrong here. The numbers from the API don’t seem to match for certain metrics. For 3/14/2024, the total Opened email is 96 for this campaign, however the API is giving 70.

Old API on the other hand matches to the UI:

However the received emails are good:
 

 

Thanks for you help!

Shikha