Skip to main content
Contributor IV
February 27, 2024
Solved

attributed_message not working?

  • February 27, 2024
  • 3 replies
  • 83 views

I am using API revision 2024-02-15.

 

 

If I do a post to https://a.klaviyo.com/api/metric-aggregates/ and I pass it the following json object in the body, it behaves as if I did not include the “by” command and does not aggregate by campaign but just gives it as if I did not specify the by.

{  
     "data": {  
          "type": "metric-aggregate",  
          "attributes": {  
               "measurements": [  
                    "count", "unique"  
               ],  
               "filter": [  
                    "greater-or-equal(datetime,2024-01-01),less-than(datetime,2024-12-31)"
               ],  
               "by": ["$attributed_message"],  
               "interval": "month",  
               "timezone": "US/Eastern",  
               "metric_id": "WhateverMetric_IdUsed"  
          }  
     }  
}

Similarly, if in the filter I indicate the campaign I wish to see, it returns nothing at all.

               "filter": [  
                    "greater-or-equal(datetime,2024-01-01),less-than(datetime,2024-12-31)",  
                    "equals($attributed_message,\"SOME_CAMPAIGN_ID\")"  
               ],  
 

isn’t $attributed_message the property to use for CampaignIds?

    This topic has been closed for replies.
    Best answer by saulblum

    Which metric are you using? Attributed message is for events like Placed Order, e.g. which campaign or flow message can the Placed Order event be attributed to. For events like Clicked Email, you’d just use $message.

    3 replies

    fpicanzaAuthor
    Contributor IV
    February 27, 2024

    Here is a little more info from another test I just performed.

    If I do "by": ["$message"]  ...

    then in what is returned there is a breakdown on a property named dimensions which contains the value of a message_Id

     

    But if I do "by": ["$attributed_message"]  ...

    then in what is returned there is a property named dimensions but it is empty.

     

    Why would it not contain the campaign_id from my campaigns?

    saulblumAnswer
    Klaviyo Employee
    February 27, 2024

    Which metric are you using? Attributed message is for events like Placed Order, e.g. which campaign or flow message can the Placed Order event be attributed to. For events like Clicked Email, you’d just use $message.

    fpicanzaAuthor
    Contributor IV
    February 27, 2024

    Once again, thank you Saulblum. That nuance did not jump at me when I was going through the examples in the doc. I did not grasp that different metrics used different properties to represent the campaign. 

    From what I’ve just tested now, I can see that either of the following will accomplish what I need

    "by": ["$message"] will get me the campaign Id
    and

    "by": ["Campaign Name"], will get me the campaign name