Adobe Analytics API 2.0

Adobe Analytics API 2.0 : Retrieving the components

The elements retrieving methods have been moved to the instance of the Analytics class.
Methods are the same but you will need to instantiate an Analytics class with your companyId before that.
Starter guide here :

In this article, I will show you how you could use the different methods of the API to retrieve and even modify some components.

Retrieve elements

Once you have established the connection for your Analytics API, you can start using the different methods to retrieve the elements.
These methods always start with get, I will not explain all of them as you will understand with one of them how it works.
I let you explore the other possibilities.

In order to retrieve the segments, you will use the “getSegments” method and this will return you a data frame of the information.

However there are some options available for these methods.
You can learn about them by looking at the docstring available with the different methods.

The docstring for segment looks like this :

Retrieve the list of segments. Returns a data frame.
name : OPTIONAL : Filter to only include segments that contains the name (str)
tagNames : OPTIONAL : Filter list to only include segments that contains one of the tags (string delimited with comma, can be list as well)
inclType : OPTIONAL : type of segments to be retrieved.(str) Possible values:
– all : Default value (all segments possibles)
– shared : shared segments
– template : template segments
– deleted : deleted segments
– internal : internal segments
– curatedItem : curated segments
rsid_list : OPTIONAL : Filter list to only include segments tied to specified RSID list (list)
sidFilter : OPTIONAL : Filter list to only include segments in the specified list (list)
extended_info : OPTIONAL : additional segment metadata fields to include on response. (bool : default False)
additional infos: reportSuiteName, ownerFullName, modified, tags, compatibility, definition
save : OPTIONAL : If set to True, it will save the info in a csv file (bool : default False)

Possible kwargs:
limit : number of segments retrieved by request. default 500: Limited to 1000 by the AnalyticsAPI. (int)

NOTE : Segment Endpoint doesn’t support multi-threading. Default to 500.

You can see now that I developed quite a few possibilities based on the Analytics API 2.0.
There are some annotation at the end of the doc string to help you understand what is expected for each parameter. Either string, integer, list or boolean.
I would not demonstrate all of them but show you some so that you can continue on your own.

The deprecated methods:

## basic call 
df_segments = api2.getSegments() ## get infos on segments
df_segments_extend = api2.getSegments(extended_info=True) ## get segments with additional info
df_segments_1000 = api2.getSegments(extended_info=True,limit=1000) ## get segments with additional info and every loop returns 1000 items. 

new methods are now hosted inside the analytics class

#instantiate the class 
cids = api2.getCompanyId()
cid = cids[0]['globalCompanyId'] ## using the first one
mycompany = api2.Analytics(cid)
## basic call 
df_segments = mycompany.getSegments() ## get infos on segments
df_segments_extend = mycompany.getSegments(extended_info=True) ## get segments with additional info
df_segments_1000 = mycompany.getSegments(extended_info=True,limit=1000) ## get segments with additional info and every loop returns 1000 items. 

I think that following that example you should get the idea on how the get methods works for the different elements.
The different elements that you can retrieve through the wrapper are :

  • reportSuites
  • dimensions (props and eVars)
  • metrics
  • calculated metrics
  • date ranges

Update elements

On top of retrieving these elements, you can also edit and/or delete some elements.
Not all of them but custom made ones such as Segments and Calculated Metrics.

At the time of that writing, the python wrapper only covers the segment editing part. It is not out of scope that I realize the calculated metrics as well in the future, and if I do, it will probably look quite similar with the same methods. Therefore, I won’t update the documentation. This example will explain you how you could realize those change.

The method to edit a segment is “updateSegment” and this method takes 2 parameters :

  • segmentID : a string of the segment ID
  • segmentJSON : the dictionary (python format of a JSON) of the segment definition containing the information you want to update.

The process to realize that is to retrieve a segment information and save the segment definition in an object.
Then, you can change the segment dictionary definition and push it to this method.

The method to delete a segment is “deleteSegment”, it requires just one parameter.

The new methods looks like this :

delSeg = mycompany.deleteSegment('mySegID') ## where mySegID is your segment id

## your segment dictionary with a new name 
#updateVersion = {
# "id": "string",
#  "name": "myNewName",
#  "description": "string",
#  "rsid": "string",
#  "reportSuiteName": "string",
#  "owner": {...
newSeg = mycompany.updateSegment('mySegID', updateVersion) ## where mySegID is your segment id

I think that this tutorial was enough for you to grasp the possibilities offer by the python wrapper with the Analytics API, regarding the different elements to retrieve.

If you are interested to learn more, you can look at these articles:

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 *