Using Adobe Omniture API with Python

On this post I will show simple examples on most report types of omniture with python.
Note that I'm using a modified api that initially was maintained by Rob Goretsky.
I only included the ranked, realtime report and clean the code a litle bit. All credits for Rob Goretsky.

Get my version of the API here.

Authentication
QueueOvertime Report
QueueTrended Report
QueueRanked Report
GetRealTimeReport





Import the api module and instanciate with your user and public secret of omniture.

from omniture import Omniture  
om = Omniture('username:company','shared_secret')


QueueOvertime Report

To get a Overtime report you can use the get_count_from_report method that will return a total number of given metric.
For example if you want get the total number of pageviews from yesterday you can run


p = om.get_count_from_report('report_suite_name', 'pageViews')
  


If you want the pageviews from other date range you can pass the date on the parameters date_from and date_to like this example where I get the pageviews from today.


from datetime import date
today = date.today().strftime("%Y-%m-%d")
p = om.get_count_from_report('report_suite_name', 
                            'pageViews', 
                            date_from=today,
                            date_to=today)
 
Let's say you don't want a total sum of pageviews and want a value per day on your specific range, for example you want the number of pageviews from yesterday and today separated on the same report. You can do this passing the parameter return_one_total_result=False.


p = om.get_count_from_report('report_suite_name', 
                            'pageViews',
                            date_to=today,
                            return_one_total_result=False
                            )
 

On the code above I omitted the date_from parameter with will get the default date from yesterday and passed the date_to with today date and return_one_total_result as False.
So the range date is from yesterday to today and the return from the code will be a dictionary with the day as key and the pageviews as value, like the result below


>>> p
defaultdict(, {u'Sat.  2 Nov. 2013': u'3120271', u'Sun.  3 Nov. 2013': u'720373'})
>>> p.keys()
[u'Sat.  2 Nov. 2013', u'Sun.  3 Nov. 2013']
>>> p['Sat.  2 Nov. 2013']
u'3120271'
>>> p['Sun.  3 Nov. 2013']
u'720373'


QueueTrended Report

To get a Trended report you have to use  the get_count_from_report method to, but the only distinction from the OverTime report is that you will pass a element as parameter that will not be time.


p = om.get_count_from_report('report_suite_name', 
                            'pageViews', 
                            'page', 
                            ["Homepage","Media Guide"]) 

On the code above I getting a trended report on the metric=Pageviews, element="page" and selected_element_list=["Homepage", "Media Guide"]. I omitted the parameters name because they are on the right order but you can pass the named parameters if you want.
The return of the code above will be a sum of pageviews between Homepage and Media Guide on a trended report. If you don't want a total sum you can set the return_one_total_result parameter as False.

QueueRanked Report

To get a Ranked report use the ranked_report method.
For example if you want to get the number of visits ranked by the type of browser, you can run
data = om.ranked_report('report_suite_name', 'visits', element='browser')
 

This will return a list of dictionaries with the browser name and the numer of visits, like this



[{u'url': u'', u'counts': [u'469468'], u'name': u'Google Chrome 30.0'},
 {u'url': u'', u'counts': [u'74709'], u'name': u'Microsoft Internet Explorer 10'},
 {u'url': u'', u'counts': [u'65520'], u'name': u'Mozilla Firefox 24.0'},
 {u'url': u'', u'counts': [u'57222'], u'name': u'::unspecified::'}, 
 {u'url': u'', u'counts': [u'20164'], u'name': u'Microsoft Internet Explorer 9'},
 {u'url': u'', u'counts': [u'19068'], u'name': u'Microsoft Internet Explorer 8'},
 {u'url': u'', u'counts': [u'15367'], u'name': u'Mozilla Firefox 25.0'}, 
 {u'url': u'', u'counts': [u'8574'], u'name': u'Google Chrome 29.0'}, 
 {u'url': u'', u'counts': [u'4361'], u'name': u'Google Chrome 28.0'}, 
 {u'url': u'', u'counts': [u'4253'], u'name': u'Google Chrome 31.0'}]

So you can iterate over the list and do whatever you want



>>> for b in data:
...   print "Browser: ", b['name'], " - Visits: ", b['counts'][0]
... 
Browser:  Google Chrome 30.0  - Visits:  469468
Browser:  Microsoft Internet Explorer 10  - Visits:  74709
Browser:  Mozilla Firefox 24.0  - Visits:  65520
Browser:  ::unspecified::  - Visits:  57222
Browser:  Microsoft Internet Explorer 9  - Visits:  20164
Browser:  Microsoft Internet Explorer 8  - Visits:  19068
Browser:  Mozilla Firefox 25.0  - Visits:  15367
Browser:  Google Chrome 29.0  - Visits:  8574
Browser:  Google Chrome 28.0  - Visits:  4361
Browser:  Google Chrome 31.0  - Visits:  4253


GetRealTimeReport

For the RealTimeReport use the real_time_report method.
To get the revenue value on run the code below.


r = om.real_time_report('report_suite_name', 'revenue')
 

Be aware that the RealTimeReport DON'T support all metrics avaiable on omniture.


Useful Links 

https://developer.omniture.com/en_US
Omniture Metrics
Omniture Elements

Deixe um comentário