Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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!'