New Calculated Metrics and the APIs

With the June update, a big feature added to Analytics and Reporting was the fancy new Calculated Metrics (a.k.a Derived Metrics). While I'm sure you've seen the update to the user interface with the new Calculated Metrics component manager, you may not be aware that everything that can be done in the UI is also available in the APIs and Reporting.

We have added API methods under a new Calculated Metrics module: CalculatedMetrics.Get (see all the calculated metrics you have access to, or as an admin, all calculated metrics for the company), CalculatedMetrics.Save (create new calculated metrics or update existing ones), CalculatedMetrics.Delete and CalculatedMetrics.GetFunctions (see the full list of allowed functions in the new calculated metrics definitions). Check them out in the API-Explorer.

What I'm most excited about is the ability to use much more powerful inline Calculated Metrics in the Reporting API. If you have used the Reporting API, then you know that you list all your metrics, and each one requires an "id" (e.g. "pageviews" or "[revenue] / [visitors]"). With the new calculated metrics, you specify a "definition" instead of an "id". In this "definition" you can specify any function or series of calculations that tickle your fancy, including anything and everything you can do in the Calculated Metrics component manager. Below are a few basic examples.

These definitions are exciting, because if you play your cards right (i.e. write good code), you can have a lot more flexibility of using calculated metrics in reports without all the hassle of creating them, retrieving them, and maintaining them across report suites or companies. Just slip the definition itself into your script and reuse it and tweak it to your heart's content.

Examples:

Like the number 100?

"definition": {
    "number": 100
}

Okay, not especially useful. How about a couple favorites?

"definition": {
    "metric": "pageviews"
}

"definition": {
    "metric": "revenue",
    "allocation": "linear"
}

Segmented revenue?

"definition": {
    "metric": "revenue",
    "allocation": "linear",
    "segments": [
        "[segment ID here, use Segments.Get to retrieve it]"
    ]
}

How about a little math?

"definition": {
    "function": "divide",
    "parameters": [
        {
            "metric": "revenue",
            "allocation": "linear"
        },
        {
            "number": 100
        }
    ]
}

There's a lot more you can do. Call CalculatedMetrics.GetFunctions to see a full list of allowed functions. Almost every item in a "parameters" list can be a number, a metric, or another function, so don't be shy, give it a try.

Interested in the documentation for the mentioned methods?

At the time of writing (Mar-2018), it's under Segments v1.4:
https://marketing.adobe.com/developer/documentation/segments-1-4/calcula...

Must be logged in to comment. now to comment!