IO alternative Google Analytics with pandas

advertisements

The pandas 0.17.1 version has depreciated the pandas.io.ga module.

What are the alternatives to using google analytics with pandas now? Is there a credible library which can be used now?


The Google2Pandas module was created to get around this specific problem. Nothing fancy, simply does what it says on the box.

v3:

from google2pandas import GoogleAnalyticsQuery

query = {\
    'ids'           : <valid_ids>,
    'metrics'       : 'pageviews',
    'dimensions'    : ['date', 'pagePath', 'browser'],
    'filters'       : ['pagePath=~iPhone', 'and', 'browser=~Firefox'],
    'start_date'    : '8daysAgo',
    'max_results'   : 10}

conn = GoogleAnalyticsQuery(secrets='client_secrets_v3.json',
                            token_file_name='analytics.dat')
df, metadata = conn.execute_query(**query)

v4:

from google2pandas import GoogleAnalyticsQueryV4

query = {
    'reportRequests': [{
        'viewId' : <valid_ids>,

        'dateRanges': [{
            'startDate' : '8daysAgo',
            'endDate'   : 'today'}],

        'dimensions' : [
            {'name' : 'ga:date'},
            {'name' : 'ga:pagePath'},
            {'name' : 'ga:browser'}],

        'metrics'   : [
            {'expression' : 'ga:pageviews'}],

        'dimensionFilterClauses' : [{
            'operator' : 'AND',
            'filters'  : [
                {'dimensionName' : 'ga:browser',
                 'operator' : 'REGEXP',
                 'expressions' : ['Firefox']},

                {'dimensionName' : 'ga:pagePath',
                 'operator' : 'REGEXP',
                 'expressions' : ['iPhone']}]
        }]
    }]
}

conn = GoogleAnalyticsQueryV4(secrets='client_secrets_v4.json')
df = conn.execute_query(query)