def test_missing_api_url(self):
     try:
         a = PiwikAnalytics()
         r = json.loads(a.send_request())
         invalid_config = True
     except ConfigurationError:
         invalid_config = False
     self.assertFalse(invalid_config)
 def test_missing_api_url(self):
     try:
         a = PiwikAnalytics()
         r = json.loads(a.send_request())
         invalid_config = True
     except ConfigurationError:
         invalid_config = False
     self.assertFalse(invalid_config)
 def setUp(self):
     """
     Set up a PiwikAnalytics instance
     """
     super(AnalyticsBaseTestCase, self).setUp()
     self.a = PiwikAnalytics()
     self.a.set_api_url(self.settings['PIWIK_ANALYTICS_API_URL'])
     self.a.set_id_site(self.settings['PIWIK_SITE_ID'])
     self.a.set_format('json')
     self.a.set_period('day')
     self.a.set_date('today')
class AnalyticsBaseTestCase(PiwikAPITestCase):
    def setUp(self):
        """
        Set up a PiwikAnalytics instance
        """
        super(AnalyticsBaseTestCase, self).setUp()
        self.a = PiwikAnalytics()
        self.a.set_api_url(self.settings.PIWIK_ANALYTICS_API_URL)
        self.a.set_id_site(self.settings.PIWIK_SITE_ID)
        self.a.set_format("json")
        self.a.set_period("day")
        self.a.set_date("today")
Beispiel #5
0
class AnalyticsBaseTestCase(PiwikAPITestCase):
    def setUp(self):
        """
        Set up a PiwikAnalytics instance
        """
        super(AnalyticsBaseTestCase, self).setUp()
        self.a = PiwikAnalytics()
        self.a.set_api_url(self.settings['PIWIK_ANALYTICS_API_URL'])
        self.a.set_id_site(self.settings['PIWIK_SITE_ID'])
        self.a.set_format('json')
        self.a.set_period('day')
        self.a.set_date('today')
Beispiel #6
0
import json
from piwikapi.analytics import PiwikAnalytics

# get live data
pa = PiwikAnalytics()
pa.set_api_url('https://audiobook.innocraft.cloud/index.php')
pa.set_id_site(1)  # 1 is the side ID you want to log to
pa.set_format('json')
pa.set_period('day')
pa.set_date('today')
pa.set_method('Live.getLastVisitsDetails')
pa.set_parameter('lastMinutes', 5)
visits = json.loads(pa.send_request())
#generates error in the variable explorer
# "You can't access this resource as it requires 'view' access for the website id = 1."

# attempt for getting image graph. Runs but does not return image.
from piwikapi.analytics import PiwikAnalytics

pa = PiwikAnalytics()
pa.set_api_url('https://audiobook.innocraft.cloud/index.php')
pa.set_id_site(1)  # 1 is the side ID you want to log to
pa.set_method('ImageGraph.get')
pa.set_parameter('apiModule', 'UserCountry')
pa.set_parameter('apiAction', 'getCountry')
image = pa.send_request()
Beispiel #7
0
def get_live_widget():
    pa = PiwikAnalytics()
    pa.set_api_url('https://collect.mayflower.live/index.php')
    pa.set_id_site(2)
    pa.set_parameter('token_auth', MATOMO_TOKEN)
    # pa.set_format('json')
    pa.set_period('day')
    pa.set_date('today')
    pa.set_parameter('module', 'Widgetize')
    pa.set_parameter('action', 'iframe')
    pa.set_parameter('widget', 1)
    pa.set_parameter('moduleToWidgetize', 'Live')
    pa.set_parameter('actionToWidgetize', 'getSimpleLastVisitCount')
    return pa.send_request()
Beispiel #8
0
def get_data(method, date):
    pa = PiwikAnalytics()
    pa.set_api_url('https://collect.mayflower.live/index.php')
    pa.set_id_site(2)
    pa.set_parameter('token_auth', MATOMO_TOKEN)
    pa.set_format('json')
    pa.set_method(method)
    pa.set_period('day')
    pa.set_date(date)
    return json.loads(pa.send_request())
Beispiel #9
0
def doSomething(dateRange, period, token):
    # you don't need to change any of these
    pa = PiwikAnalytics()
    pa.set_api_url('https://analytics.ida.digital.cabinet-office.gov.uk/index.php')
    pa.set_id_site(1) # 1 is the side ID you want to log to
    pa.set_format('json')
    pa.set_period(period)
    pa.set_date(dateRange)
    pa.set_parameter('module', 'API')
    pa.set_parameter('token_auth', token)

    # the default is 100. For all results, set to -1. Using 1 when you're building
    # script is helpful for debugging when you're writing your script.
    pa.set_parameter('filter_limit', '1')

    # change these to the method and segment you need
    pa.set_method('Actions.getPageTitles')
    pa.set_segment('referrerName=@universal-credit')



    visits = json.loads(pa.send_request())
    # print the json to see the labels of the fields you need to retrieve
    print json.dumps(visits, indent=4)

    # extract the data from the json. You'll need to put it in a loop when
    # you have more than one item in visits
    pageTitle = visits[0]['label']
    uniques = visits[0]['sum_daily_nb_uniq_visitors']
    print pageTitle, uniques
Beispiel #10
0
def getVisitDetails(dateRange, period):
    pa = PiwikAnalytics()
    pa.set_api_url('https://analytics.ida.digital.cabinet-office.gov.uk/index.php')
    pa.set_id_site(1) # 1 is the side ID for live
    pa.set_format('json')
    pa.set_period(period)
    pa.set_date(dateRange)
    pa.set_method('Live.getLastVisitsDetails')
    pa.set_parameter('module', 'API')
    pa.set_parameter('expanded', '1')
    pa.set_segment('customVariableValue2=@XXX;pageTitle=@Success - REGISTER_WITH_IDP')
    # custom variable 2 is IDP
    pa.set_parameter('countVisitorsToFetch', '-1')
    # -1 is 'get all of them'
    pa.set_parameter('token_auth', 'XXX')

    IDP = json.loads(pa.send_request())
    #print json.dumps(fails, indent=4)

    print len(IDP)

    for item in IDP:
        try:
            details = list()
            visitorIP = item["visitIp"]
            details.insert(0, visitorIP)
            cv1 = item["customVariables"]["1"]["customVariableValue1"]
            details.insert(0,cv1)
            opSys = item["operatingSystem"]
            details.append(opSys)
            visits = item["visitCount"]
            details.append(visits)
            days = item["daysSinceFirstVisit"]
            details.append(days)

            print details
        except:
            print 'Ooops!'
Beispiel #11
0
def doSomething(dateRange, period, token):
    # you don't need to change any of these
    pa = PiwikAnalytics()
    pa.set_api_url(
        'https://analytics.ida.digital.cabinet-office.gov.uk/index.php')
    pa.set_id_site(1)  # 1 is the side ID you want to log to
    pa.set_format('json')
    pa.set_period(period)
    pa.set_date(dateRange)
    pa.set_parameter('module', 'API')
    pa.set_parameter('token_auth', token)

    # the default is 100. For all results, set to -1. Using 1 when you're building
    # script is helpful for debugging when you're writing your script.
    pa.set_parameter('filter_limit', '1')

    # change these to the method and segment you need
    pa.set_method('Actions.getPageTitles')
    pa.set_segment('referrerName=@universal-credit')

    visits = json.loads(pa.send_request())
    # print the json to see the labels of the fields you need to retrieve
    print json.dumps(visits, indent=4)

    # extract the data from the json. You'll need to put it in a loop when
    # you have more than one item in visits
    pageTitle = visits[0]['label']
    uniques = visits[0]['sum_daily_nb_uniq_visitors']
    print pageTitle, uniques