Adobe Analytics API 2.0 : Reporting

EDIT : MAJOR UPDATE
The reporting functionality has been moved to the instance of the Analytics class.
The method is the same but you will need to instantiate an Analytics class with your companyId before that.

Starter guide here : https://github.com/pitchmuc/adobe_analytics_api_2.0/blob/master/docs/getting_started.md

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 : OPTIONAL : Number of result that you would like to retrieve. (default 1000)
    if you want to have all possible data, use “inf”.
  • item_id : OPTIONAL : if you want to return the itemId for subsequent calls based on the data returned.
  • 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

11 thoughts on “Adobe Analytics API 2.0 : Reporting

  1. requesting help on the following:
    when i run
    import aanalytics2 as api2
    api2.importConfigFile(‘config_admin.json’)
    cids = api2.getCompanyId()
    cid = cids[0][‘globalCompanyId’] ## using the first one
    mycompany = api2.Analytics(cid)
    select_id=cids[0][‘globalCompanyId’]
    select_id
    api2.updateHeader(select_id)

    Getting an error message
    Traceback (most recent call last):
    File “C:\Users\user0\PycharmProjects\data_viz\venv\lib\site-packages\IPython\core\interactiveshell.py”, line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    File “”, line 8, in
    api2.updateHeader(select_id)
    AttributeError: module ‘aanalytics2’ has no attribute ‘updateHeader’

    any insights into the “updateHeader” error.
    Note: cid returns right value. I am using your latest aanalytics.py posted 2 days back

    1. Hello Raj,
      Sorry I didn’t update this post at the same time.
      You don’t need to updateHeader anymore. This is automatically done when you are creating the instance of Analytics class.
      So to use the report, you will need to do the following :

      myreport = mycompany.getReport(myRequestJSON)

  2. Hi Julien,
    I was also looking for breakdown of One dimension say “countries” by day granularity, will it work ? any directional idea would be super helpful.
    Thank you so much for your API 2.0 work

    1. Hello Raj,
      You would need to do a 2nd request with the id of the other. Countries will be your filter metrics and day will be your dimension.
      Most probably you will need to do these requests :
      1 for getting the dimensions,
      1 for getting the metrics on a daily granularity… per country.

      Then you can either do the same 2nd request for every countries or include as many filters (and metrics) as you have countries.

  3. Hi, I tried the code, but the getReport(‘request.json’) is a dict class. I tried the code that extracts data from the dict. I looked up several other panda modeles, especially, pandas.DataFrame.from_dict() doesnt work. I tried the orient as columns, but no use. Can you help me extract the data from the JSON report?

  4. Hello,

    I looked at the data for bulkapi. but everytime I try its shows the below error. I am using python 3.6 in azure notebooks.

    ModuleNotFoundError Traceback (most recent call last)
    ~/anaconda3_501/lib/python3.6/site-packages/aanalytics2/ingestion.py in __init__(self, endpoint)
    113 try:
    –> 114 import importlib.resources as pkg_resources
    115 except ImportError:

    ModuleNotFoundError: No module named ‘importlib.resources’

    During handling of the above exception, another exception occurred:

    ModuleNotFoundError Traceback (most recent call last)
    in
    2
    3 ## Instanciate with European servers
    —-> 4 bulkapi = ingestion.Bulkapi(endpoint=”https://analytics-collection-nld2.adobe.io “)

    ~/anaconda3_501/lib/python3.6/site-packages/aanalytics2/ingestion.py in __init__(self, endpoint)
    115 except ImportError:
    116 # Try backported to PY 117 import importlib_resources as pkg_resources
    118 path = pkg_resources.path(
    119 “aanalytics2”, “CSV_Column_and_Query_String_Reference.pickle”)

    ModuleNotFoundError: No module named ‘importlib_resources’

    1. Thanks for that comment.
      importlib.resources is only available on 3.7, but it seems that importlib is not installed at all on your python installation.
      Normally importlib is a default package on python 3(https://docs.python.org/3/library/importlib.html)
      I tried another way to handle that issue in the new version I published today.
      Could you upgrade your version of aanalytics2 ? by doing pip install aanalytics2 –upgrade. It is the version 0.0.8.
      you can see that by doing aanalytics2.__version__ in your jupyter notebook.

      Hopefully that solve your problem.
      If it doesn’t, can you please fill an issue here : https://github.com/pitchmuc/adobe_analytics_api_2.0/issues

Leave a Reply

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