Aggregation by User Attribute

I'm working through the API documentation and have run into a snag. The body code below works perfectly for returning time-bound counts aggregated by the User's agent.

{
  "response": {
    "mimeType": "application/json"
  },
  "request": {
    "name": "os-chart-count-by-browser",
    "pipeline": [{
      "source": {
        "events": {
          "eventClass": ["web", "ios"]
        },
        "timeSeries": {
          "period": "dayRange",
          "first": "now()",
          "count": -30
        }
      }
    }, {
      "identified": "visitorId"
    }, {
      "group": {
        "group": ["visitorId", "userAgent"]
      }
    }, {
      "useragent": {
        "userAgent": "userAgent"
      }
    }, {
      "group": {
        "group": ["userAgent.os"],
        "fields": [{
          "count": {
            "count": null
          }
        }]
      }
    }, {
      "select": {
        "count": "count",
        "os": "userAgent.os"
      }
    }, {
      "sort": ["-count"]
    }],
    "requestId": "os-chart-count-by-browser"
  }
}

 

What I'd like to do is to run the same type of query, but aggregate by visitor attributes. For instance, our visitors have language (
visitor.visitor_agent_language), agent attributes (visitor.userAgent_deviceType) and a bunch of custom visitor attributes like the user's permission group in our application (visitor.visitor_agent_userpermissiongroups_ap) that I'd like to return aggregate totals.

My desired result for something like that User Permissions attribute would be:
 
{
    "startTime": 1682049600000,
    "results": [
        {
          "AP Permissions": "Contributor",
            "count": 4932
        },
        {
          "AP Permissions": "Administrator",
            "count": 55
        },
        {
          "AP Permissions": "Read Only",
            "count": 3
        },
        {
          "AP Permissions": "None",
            "count": 1
        }
    ]
}

How would I construct the body of an Aggregate query to pull counts of page load events by these Visitor attributes?

1

コメント

4件のコメント
  • If you're looking specifically for page events, then you'd want to use the pageEvents source and an aggregation similar to this one below. The bulkExpand will take the visitors returned and pull all of the current metadata values for them. You can then reference any of the metadata you listed and use it to aggregate the data.
     
    {
        "response": {
            "mimeType": "application/json"
        },
      "request": {
            "pipeline": [
                {
                    "source": {
                        "pageEvents": null,
                        "timeSeries": {
                            "period": "dayRange",
                            "first": "now()",
                            "count": -30
                        }
                    }
                },
                {
                    "identified": "visitorId"
                },
                {
                    "group": {
                        "group": [
                            "visitorId"
                        ],
                        "fields": {
                            "numEvents": {
                                "sum": "numEvents"
                            }
                        }
                    }
                },
                {
                    "bulkExpand": {
                        "visitorMetadata": {
                            "visitor": "visitorId"
                        }
                    }
                },
                {
                    "group": {
                        "group": [
                          "visitorMetadata.agent.language"
                        ],
                        "fields": [
                            {
                                "visitorCount": {
                                    "count": null
                                }
                            },
                            {
                                "numEvents": {
                                    "sum": "numEvents"
                                }
                            }
                        ]
                    }
                },
                {
                    "select": {
                        "Event Count": "numEvents",
                        "Visitor Count": "visitorCount",
                      "Language": "visitorMetadata.agent.language"
                    }
                }
          ]
        }
    }

    This would return something like this (taken from my test account): 

    {
        "startTime": 1682222400000,
        "results": [
            {
                "Event Count": 245,
                "Visitor Count": 7,
              "Language": "en_US"
            },
            {
                "Event Count": 1042,
                "Visitor Count": 1,
                "Language": "en_GB"
            }
        ]
    }
    1
  • Oh my - so much to unpack here. First of all - this works perfectly so thank you so much! I had been digging through the Engage API documentation (https://engageapi.pendo.io/) and it is NOT easy to find the Operators documentation. With your code above, I was able to google up a cleaner description of that function here (https://adoptpartners.pendo.io/hc/en-us/articles/360043366692-API-Documentation#operators). Thank you again - you have cleared the clog!

    0
  • Alisyn-Collins - would it be possible to apply a filter to your query that only returned Event Counts (numEvents) greater than 0?

    0
  • Steve Krile, yes indeed!  You'd want to just add a filter operator just before the select like this:

    {
        "filter": "numEvents > 0"
    },
    {
        "select": {
            "Event Count": "numEvents",
            "Visitor Count": "visitorCount",
            "Language": "visitorMetadata.agent.language"
        }
    }
    0

サインインしてコメントを残してください。

お探しのものを見つけられませんでしたか?

新規投稿