The Statement Class in the Python Adobe Analytics API
This Class (or method in the library) will provide you some additional methods to manipulate the statement you want to use for the Adobe Analytics API.
The important information is that this is a class and therefore an instance hast to be created to really use this element.
A statement is a variable that will inherit all the method of this class, it will enable you to work with the statement as a specific object.
As an example, you will need to have the structure of a statement more or less ready and create your instance from it.
It can be a file or an object that host that dictionary.
You can an introduction to Adobe Analytics statement on this page : adobe analytics API statement.
##from an object
my_statement = aanalytics.Statement(obj=my_dict)
##from a file
my_statement = aanalytics.Statement(obj=my_dict)
The methods
This class as several methods available to help you modify your statement :
- add_metrics : takes as many arguments as possible (they should be valid metrics) and add them to the statement
example : my_statement.add_metrics(‘event1′,’event89’)
- remove_metrics : takes as many arguments as possible (they should be valid metrics) and remove them from the statement
example : my_statement.remove_metrics(‘event1′,’event89’)
- add_segments : takes as many arguments as possible (they should be valid segment id) and add them to the statement
example : my_statement.add_segments(‘s919_5acc884e01c1ebd9723af245’)
- remove_segments : takes as many arguments as possible (they should be valid segment id) and remove them from the statement
example : my_statement.remove_segments(‘s919_5acc884e01c1ebd9723af245’)
- add_dimensions : this method work a bit differently than the other 2 before. It takes dictionary (key : value pair) and append them to the list of dimension. The minimal key value pair that need to be set for this variable is {“id”:”evarX”} (or propX).
example : my_statement.add_dimensions({‘id’:’evar59′})
You can, of course, add more information to your dictionnary, like the selected element you want, per example : {‘id’:’evar59′,’selected’:[‘valueA’,’valueB’]}, see the Adobe Documentation for more information : github_elements
- remove_dimensions : the same way that it is set before, it takes the full dictionary and remove it from the list of dimension available.
The recommended way to realize that is to retrieve the element that you want to retrieve in a variable, or look for it using the dimensions attribute. (see attribute section)
example : my_statement.remove_dimensions(my_statement.dimensions[0])
- add_granularity : this method enables you to add the granularity that you want to your report.
The different type of granularity available are listed here : github_granularity
example : my_statement.add_granularity(‘month’)
- remove_granularity : this method remove the granularity of your report. No argument required.
example : my_statement.remove_granularity()
- add_top : this method takes the dimension as argument and the top you want to apply to this dimension.
The default number of rows return by Adobe API is 10 rows. With top, you can request up to 50 000 rows.
example : my_statement.add_top(dim=”evar1″,top=1000) ## will return the 100 first lignes
- change_dates : this method takes 2 arguments, start & end, it changes your statement dates.
example : my_statement.change_dates(start=”2018-01-01″,end=”2018-01-31″)
The attributes
The Statement class is not only coming with method, it also coming with special attributes built from the statement you passed on the creation of the instance.
- start_dates : This attribute gives you the starting date of your report.
Important : it is not setting a new starting date in your statement if your change this attribute.
- end_dates : This attribute gives you the starting date of your report.
Important : it is not setting a new end date in your statement if your change this attribute.
- metrics : this attribute gives you the metrics in your statement.
Important : it is not setting new metrics if your change this attribute but it will follow the change made through the different methods available.
- segments : this attribute gives you the segments used in your statement.
Important : it is not setting new metrics if your change this attribute but it will follow the change made through the different methods available.
- dimensions : this attribute gives you the dimensions used in your statement.
Important : it is not setting new metrics if your change this attribute but it will follow the change made through the different methods available.
- statement : this attribute return the statement that you manipulate as dictionary
On this series, you may want to read as well :
Article | Content |
Introduction | What is to know about the Adobe Analytics API with Python |
Requirements | What is necessary to know and to be done before you start with the aanalytics module |
Statement creation | What is a statement and why is it import for the API |
Statement Class | What is a the statement Class and how can it help you created a statement |
Getelements method | Explanation on how the getElements method works |
Getelements method | Explanation on how the getReport method works |
Getelements method | Explanation on how the retrieveReport method works |