Adobe Analytics API 2.0 : Reporting

As I was explaining in the my previous article on the Analytics API 2.0, the new API is just the programmatic view on Analytics Workspace.
In my humble opinion, it should have been called the Workspace API.

It has implication overall, good and bad. I already focus mostly on them and don’t want to open that discussion again, so let’s stick with what is possible to do with the API.

Use of Workspace to create your statement

As you may be familiar with API usage, usually you do have a statement that you are delivering to the API. This statement states several things and you hope that the API can answer it and returns you the result.

The good news with the Adobe Workspace API is that you can actually generate the statement without too much worries.
The way it is done is that you can build your basic workspace report in Adobe Analytics Workspace and use a developer console trick to display what the JSON statement looks like.

This opportunity was too beautiful to let pass, so I make sure that you can use the JSON statement provided by Adobe Analytics Workspace into the Adobe Analytics API 2.0 python wrapper.

I could try to explain that but Adobe did a better job than what I could possible do so here is the video, available on youtube.

Using Workspace to Build Adobe Analytics API request

As you can see in that video, it is quite easy to realize that (drag and drop).
It can be quite difficult to create statements and this option is definitely the easiest one around.

I was thinking of creating a class to help user create this kind of statement directly from the API but I don’t think it is quite necessary for now.

When you have retrieve this JSON statement, you can actually copy and save it into a “.json” file.
This file will be used to realize the request.
Actually, you can also just pass the JSON statement as dictionary as well if you want, but it may be quite difficult to debug for beginners, so I would recommend the 2 steps process if you are not familiar with the difference between JSON and python dictionaries.

You can directly ask for the report by using this file and the getReport method. It will return you an object.

Note :
There are some parameters available for the getReport method.
Those parameters are :

  • json_request : JSON statement that contains your request for Analytics API 2.0.
    The argument can be :
    – a dictionary : It will be used as it is.
    – a string that is a dictionary : It will be transformed to a dictionary / JSON.
    – a path to a JSON file that contains the statement (must end with “.json”)
  • n_result : Number of result that you would like to retrieve. (default 1000)
    if you want to have all possible data, use “inf”.
  • save : OPTIONAL : If you would like to save the data within a CSV file. (default False)
  • verbose : OPTIONAL : If you want to have comment display (default False)

Response Object from Analytics API

For the few of you that have used my Analytics 1.4 API, you may remember that I was always returning a dataframe from all the different response you had.

For the Analytics 2.0 API, I have considered a different approach for several reasons :

  • The different context that can be used in the Workspace
    On the 1.4 API, you could only apply segment on top of your report, so by a naming convention, it was quite easy to remember what you were doing and which context apply.
    With the 2.0, you can apply segment on top of your report but also on your different metrics.
  • The naming convention was not enforced and the context information could be lost.
  • It gives you additional insights on your past request or on how the report is being built on.

The object is containing the following keys :

  • dimension : the dimension that the report is being built on
  • filters : a dictionary that gives you global filters (filters that apply on top of your workspace project) or the metric filters (segment or dimensions used on top of metrics).
  • reportSuiteId : the reportSuite that has been used for that report
  • metrics : the metrics that has been used in the report
  • data : this is the dataframe that contains all of your data that have been requested.

At the end your code could look like :

I hope that this series of articles were useful to understand the Analytics API 2.0 python wrapper.
You can always leave a comment and check the other articles related :

ArticlesComments
Adobe IO : JWT authenticationHow to create JWT authentication with OpenSSL and python
Adobe IO : Analytics API 2.0 : IntroductionWhat you need to know about this module
Adobe IO : Analytics API 2.0 : Connection to Analytics Getting started with the python wrapper.
Adobe IO : Analytics API 2.0 : Retrieving ElementsHow to retrieve evars, metrics, users, segments, etc…
Adobe IO : Analytics API 2.0 : Reporting How to get a report from the new Analytics API 2.0
Adobe IO : Analytics API 2.0 : Tutorial Video to demonstrate how to use the Analytics API 2.0 with the python wrapper

Leave a Reply

Your email address will not be published. Required fields are marked *