Adobe Audience Manager API

AAM API : The AudienceManagerData Class

On this article I will explain why I created this class in my API and how it can be useful to you. I will cover how to instance that class and which methods are available for you.

Why a class?

I created a class for this module because I wanted to be able to modify, search in the information I have fetched from the returnAudienceData method.
The returnAudienceData method is a nice starts but for a rich account it is quite hard to use efficiently all those data. You would need to use Excel and create VLookUp or PivotTable. Then to modify the segment you want, it would be possible but quite hard to that by batch.

At the end, Excel is a very good tool when you are picking your data but for batch modification and for relational search, it is quite limited and not so efficient. You can use different pandas data frame and merge them on their key, but doing that regularly is quite boring, therefore I automatized the most common method that users are doing for Traits and Segments in that class. Also the instance store the information automatically so you don’t need to import them over and over again.

Under the hood, it is using python pandas, therefore you can do the same yourself if you want to do something very specific. If you think that this is a very important method, feel free to drop me a mail and I would try to implement it.

How to create your instance?

When you have retrieved the data from your account, using the returnAudienceData, you would have normally store this information in a variable, let’s call it data. You would also have a normally a saved version of your data in an Excel file.

You can instance the class using both information.
It means that you just need to pass this information in the Class and it will automatically create the instance with those information.
I would always recommend to use the variable as the information are already in memory and parsed as data frame.

data = aaudience.returnAudienceData()
myInstance = aaudience.audienceManagerData(data)

2nd method :

myInstance = aaudience.audienceManagerData(r'C:\Users\user\Your\Folder\aaudience\report_aam_partnerName_date.xlsx')

Consider using the raw option (r prefix) before your path.

Which methods are available from my instance?

When you have loaded the data in your instance, some methods and data point will be available on this instance :

  • myInstance.data : this will return you the same type of element (dict) than the returnAudienceData methods.
    If you have loaded past data and you want to deal with the data manually without the pre existing methods I have created, you can call this method and it will return the different data frame that are hosted.
    You can even directly call the data frame you wish : mySegments = myInstance.data[‘Segments’]
  • myInstance.segmentSearch and myInstance.traitSearch : These methods will enable to… search for segments and traits. 🙂
    Different parameters are possible to be used on those search. They will return the data frame that has been found.
    At the moment you can only use one parameter at a time.
    The different parameters available for both methods :

    • name : will search for the pattern you have used using ReGex
    • sid : will try to match EXACTLY your sid
    • ic : will try to match EXACTLY your integration code
    • rule : will search for the pattern you have used using ReGex in the TraitRule
    • ds_id : will try to match EXACTLY your data source id
    • ds_name : REQUIRED datasource data table : will search for the pattern you have used using ReGex in the data source name
    • f_id : will try to match EXACTLY your folder id
    • f_name : REQUIRED Traits Folder data table : will search for the pattern you have used using ReGex in the Folder name
  • myInstance.segmentChange and myInstance.traitChange : These methods will enable to… change for segments and traits. 🙂
    Different parameters are possible to be used on those search. The method will return the data frame that has been changed.
    The different parameters available :

    • columnToChange : REQUIRED : Column to look for applying the change
    • oldValue : REQUIRED : Value to be replaced (ReGex)
    • newValue : REQUIRED : Value that will be set (ReGex)
    • condition : OPTIONAL : dictionary such as {<col>:<condition to look for>}, if you want to preselect specific trait. The condition is match exactly.
      Only one condition is supported at the moment.
  • myInstance.createTemplateNew and myInstance.createTemplateUpdate : Those 2 methods will enable you to create template to create new traits or segments or to update traits or segments.
    You need to tell which kind of data you would like to have a template about and it will return you this as data frame.
    The minimum amount and type of column you need to have for both. It will also create a csv document with these information in your working folder.

    templateTrait = myInstance.createTemplateNew('traits')
  • myInstance.Template : This data point will store the different template you have generated with the createTemplate methods.

As always with python, you don’t need to read the documentation when using the API to discover what the method is making.
You can always call the help function and I hope my comments will help you to navigate through the different methods.

help(myInstance.traitSearch)

On this series, you may want to read those other articles :

Leave a Reply

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