Solved

Campaign Performance Report

  • 5 October 2023
  • 6 replies
  • 256 views

Badge +2

Hi,

 

We have been struggling to get the appropriate data using the new version of the API. The reason for this is because the results from the dashboard do not match the ones from the API. So, the question is how to create an exact match of the Campagin Performance Report using the API service? We believe that if we are able to figure this out, we should be able to replicate the other reports too. Firstly, let’s assume we want this report:
 

 

Which in return gives us (not all data is shown for simplicity):
 

 

Our implementation, step by step:

  • We are using the python sdk (API returns similar results too) https://github.com/klaviyo/klaviyo-api-python
  • We get the metric id by running: client.Metrics.get_metrics() (In this case, open emails id is LwHApy and Placed Order one is VKACVC)
  • Then we call the campaign api to get the campaign info. 
    client.Campaigns.get_campaigns(
    filter=(
    f"greater-or-equal(created_at,{date_from}),"
    f"less-or-equal(created_at,{date_to}),"
    "equals(messages.channel,'email')"
    ),
    include=["campaign-messages"],
    )
  • Next, we call the metric-aggregates endpoint two times to get the open emails metric and total placed orders
           body = {
    "data": {
    "type": "metric-aggregate",
    "attributes": {
    "metric_id": metric.get("id"),
    "interval": "day",
    "page_size": 500,
    # "page_cursor": "",
    "timezone": "UTC",
    "measurements": ["count", "sum_value", "unique"],
    "filter": [
    f"greater-or-equal(datetime,{date_from})",
    f"less-than(datetime,{date_to})",
    ],
    # "return_fields": [metric.get("id")],
    "by": ["$attributed_message"],
    },
    }
    }
    metric_aggregates = client.Metrics.query_metric_aggregates_with_http_info(body)
  • Issues after running metric-aggregates:
    • Placed Order: Result does not match with the one from the dashboard for the same campaign id.
    • Open emails: Returns no dimension data, only results. So, how to know which data belongs to what campaign id.

Although the API works, the data returned is not the same with the one we get from the dashboard. The question here is: What are the necessary steps to reach to the same result as in the dashboard? 

 

We are happy that the new API is much more powerful than the older version, but it is somewhat unclear what should be the combination of fields such that the data returned matches the dashboard.

 

 

icon

Best answer by Brian Turcotte 5 January 2024, 19:00

View original

6 replies

Userlevel 7
Badge +36

Hi @windsor.ai!

Have you seen our expanded guide on using this endpoint for reporting?

 

This guide covers how to balance API reports to match the UI dashboards, which can change depending on your exact use case/reporting needs.

 

Best,

Brian

Badge +2

Hi,

 

Thanks for the message.

 

Yes, we have gone through the guide before. However, the guide does not address two things:

  1. Merging/joining of various api endpoints. For example, it does not cover how to join the campaign and metric-aggregates endpoints. The metric-aggregates endpoint does not always return dimensions to join the data to the campaigns. But in your reports this merging is happening.
  2. The values returned from the metric-aggregates do not always match those of your dashboard.

 

We would really appreciate a tutorial on how to create an X UI report through the API such that this knowledge can be generalized for the rest of the reports. Or, maybe guiding us on the questions above to reproduce the values. 

 

Best wishes

 

Userlevel 7
Badge +36

Hi @windsor.ai!

My apologies for the delay here! The API team is working on something to address this use case, so I will update the thread when there’s more information avialable.

 

Best,

Brian

Hi, i have a similar problem. I am not sure how to join data received from the query metric aggregation endpoint with campaign details.

Any help with this would be greatly appreciated. 
Cheers

Userlevel 7
Badge +36

Hi @Adverity!

Our API team is currently working on a way to streamline this so I’ll update the thread when I have more information!

Best,

Brian

Hi Brian,

Is there any update regarding this?

Seeing how v1-2 of the API is going to retire in June, 2024 we are quite pressed with time.
Cheers

Reply