Solved

Looking for example on getting all the profiles that performed an activity on a campaign

  • 26 February 2024
  • 9 replies
  • 74 views

Userlevel 1
Badge +1

On the site when I go to https://www.klaviyo.com/metric/VGrXMr/XXXXXXX/clicked-email or https://www.klaviyo.com/metric/XXXXXXX/feed/active-on-site   (I’ve masked the metric ids here) and I get a list of all the profiles who have had the “Clicked Email” or the “Active on Site” event. 

I need to do this through the API but the only examples I have found for this type of thing are for V1 or V2. Where can I find a sample for this that uses the stable/modern API versions ?

 

 

 

icon

Best answer by saulblum 26 February 2024, 21:40

View original

9 replies

Userlevel 4
Badge +7

There’s a handy comparison chart for the new API.

 

Get Events and filtering on the metric ID will get you all events for a given metric.

Userlevel 1
Badge +1

Hi Saulblum,

I appreciate your proposed solution but I have checked that comparison chart and I do not find anything for what would have been api/v1/metric/{metric_id}/profiles in the old version. :(

 

Userlevel 4
Badge +7

You can call add ?include=profile to the URL and the response will have an included section that shows the properties of each profile, reference by ID returned for each event.

 

 

Userlevel 1
Badge +1

That will do the trick! Thanks a whole bunch!  

Userlevel 1
Badge +1

Hi Saulblum,

If I look at my campaigns on the Klaviyo site, I can see the Open, Clicked and Active on site numbers on the page shown in the screenshot. 

 

I wanted to get the profile_id of people that fall under each of those events for each of the campaigns. I’ve been mostly successful thanks to your help. 

For the Open and the Clicked events, I’ve used https://a.klaviyo.com/api/events/?filter=equals(metric_id,"METRIC_ID") to get info on the "clicked-email" metric and for the "opened-email" and I was able to tie each instance to a campaign by looking at the property  attributes.event_properties.CampaignName for the campaign name and looking at attributes.event_properties.message for the CampaignId. 

 

 

However when I do the same for the metric Active on site, I can’t get the same because the CampaignName, and $message are not returned by the call to the API for that metric. Only a tiny subset  of the properties is returned as shown below.

 

Since on the first screenshot of this reply it shows the Active on Site for each campaign, I know it is feasible to the event to a campaign but how is it done for that one? 

Userlevel 4
Badge +7

It’s possible conversion metrics without associated monetary values, like Active on Site, are handled differently in the Get Events response.

You may be interested in the new reporting API, e.g. Query Campaign Values, that will return what you see in the UI. You can set the ID of the conversion metric, e.g. Active on Site:

 

Userlevel 1
Badge +1

I have tried it but it does not seem to work. 

in this screenshot we see that my recipients under Open rate is 4037, Click Rate is 162 and Active on Site is 44

 

Here is the body of my request posted to https://a.klaviyo.com/api/campaign-values-reports/ where there was no options for Active on site in the statistic drop-down of https://developers.klaviyo.com/en/reference/query_campaign_values so I have put its metric_id in the Conversion metric id as you suggested...

{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "statistics": [
        "clicks_unique",
        "opens_unique"
      ],
      "timeframe": {
        "start": "2024-01-01T00:00:00",
        "end": "2024-12-31T23:59:59"
      },
      "conversion_metric_id": "METRIC_ID_FOR_ACTIVE_ON_SITE",
      "filter": "and(equals(campaign_id,\"CAMPAIGN_ID\"),contains-any(send_channel,[\"email\",\"sms\"]))"
    }
  }
}

 

Running this returns the following properties shown in the screenshot below. We can see the 162 clicks and 4037 open but nothing about the 44 Active on site. 

 

 

Userlevel 4
Badge +7

Does conversion_uniques work in the statistics array?

Userlevel 1
Badge +1

Yes it does. Thank you so much Saulblum. It’s a good thing that you are around to spread this knowledge as simply reading the docs by themselves do not make a clear enough on how to go about achieving this. That makes you a priceless resources! Thanks again!

 

Reply