예제 #1
0
    def get_ga_service(self):
        service = build('analytics', 'v3', http=self.client)
        raw_accounts = service.management().accounts().list().execute(
        )['items']
        accounts = [
            account.Account(raw, service, self.client.credentials)
            for raw in raw_accounts
        ]

        self.accounts = addressable.List(accounts,
                                         indices=['id', 'name'],
                                         insensitive=True)

        return addressable.List(accounts,
                                indices=['id', 'name'],
                                insensitive=True)
예제 #2
0
def authenticate(credentials):
    client = credentials.authorize()
    service = discovery.build('analytics', 'v3', http=client)
    raw_accounts = service.management().accounts().list().execute()['items']
    accounts = [
        account.Account(raw, service, credentials) for raw in raw_accounts
    ]
    return addressable.List(accounts, indices=['id', 'name'], insensitive=True)
예제 #3
0
def authenticate(credentials):
    client = credentials.authorize()
    service = discovery.build("analytics",
                              "v3",
                              http=client,
                              cache_discovery=False)
    raw_accounts = service.management().accounts().list().execute()["items"]
    accounts = [
        account.Account(raw, service, credentials) for raw in raw_accounts
    ]
    return addressable.List(accounts, indices=["id", "name"], insensitive=True)
예제 #4
0
    def __init__(self, raw, query):
        self.raw = []
        self.queries = []

        registry = query.api.all_columns
        headers = [registry[header['name']] for header in raw['columnHeaders']]
        self.slugs = [header.pyslug for header in headers]
        self.names = [header.name for header in headers]
        self.row_cls = collections.namedtuple('Row', self.slugs)
        self.headers = addressable.List(headers,
            indices=registry.indexed_on, insensitive=True)
        self.metrics = set()
        self.dimensions = set()
        self.rows = []
        self.append(raw, query)
예제 #5
0
    def profiles(self):
        """
        A list of all profiles on this web property. You may
        select a specific profile using its name, its id
        or an index.

        ```python
        property.profiles[0]
        property.profiles['9234823']
        property.profiles['marketing profile']
        ```
        """
        raw_profiles = (self.account.service.management().profiles().list(
            accountId=self.account.id,
            webPropertyId=self.id).execute()["items"])
        profiles = [Profile(raw, self) for raw in raw_profiles]
        return addressable.List(profiles,
                                indices=["id", "name"],
                                insensitive=True)
예제 #6
0
    def webproperties(self):
        """
        A list of all web properties on this account. You may
        select a specific web property using its name, its id
        or an index.

        ```python
        account.webproperties[0]
        account.webproperties['UA-9234823-5']
        account.webproperties['debrouwere.org']
        ```
        """

        raw_properties = (self.service.management().webproperties().list(
            accountId=self.id).execute()["items"])
        _webproperties = [WebProperty(raw, self) for raw in raw_properties]
        return addressable.List(_webproperties,
                                indices=["id", "name"],
                                insensitive=True)
예제 #7
0
    def webproperties(self):
        """
        A list of all web properties on this account. You may
        select a specific web property using its name, its id
        or an index.

        ```python
        account.webproperties[0]
        account.webproperties['UA-9234823-5']
        account.webproperties['debrouwere.org']
        ```
        """

        #raw_properties = self.service.management().webproperties().list(
        #    accountId=self.id).execute()['items']

        raw_properties = [{'accountId': 'ACCT_0',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2006-06-07T20:01:28.000Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_0',
          'id': 'UA-ACCT_1-1',
          'industryVertical': 'UNSPECIFIED',
          'internalWebPropertyId': 'WEB_0',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_0',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 14,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2020-01-14T18:50:03.686Z',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2013-10-29T19:06:37.094Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_1',
          'id': 'UA-ACCT_1-3',
          'industryVertical': 'OTHER',
          'internalWebPropertyId': 'WEB_1',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_1',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:31:06.244Z',
          'websiteUrl': 'http://sitename_1'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2013-10-29T19:26:40.176Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_2',
          'id': 'UA-ACCT_1-4',
          'industryVertical': 'UNSPECIFIED',
          'internalWebPropertyId': 'WEB_2',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_2',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:31:22.440Z',
          'websiteUrl': 'http://sitename_2'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2013-10-29T21:42:12.067Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_3',
          'id': 'UA-ACCT_1-5',
          'industryVertical': 'OTHER',
          'internalWebPropertyId': 'WEB_3',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_3',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:30:48.975Z',
          'websiteUrl': 'http://sitename_3'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2014-03-04T23:17:50.901Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_4',
          'id': 'UA-ACCT_1-6',
          'industryVertical': 'OTHER',
          'internalWebPropertyId': 'WEB_4',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_4',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:30:21.291Z',
          'websiteUrl': 'http://sitename_4'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2014-06-11T18:16:42.616Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_5',
          'id': 'UA-ACCT_1-7',
          'industryVertical': 'OTHER',
          'internalWebPropertyId': 'WEB_5',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_5',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:31:45.706Z',
          'websiteUrl': 'https://sitename_5'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles',
          'type': 'analytics#profiles'},
          'created': '2017-09-12T21:58:59.630Z',
          'dataRetentionResetOnNewActivity': True,
          'dataRetentionTtl': 'INDEFINITE',
          'defaultProfileId': 'PROF_6',
          'id': 'UA-ACCT_1-8',
          'industryVertical': 'OTHER',
          'internalWebPropertyId': 'WEB_6',
          'kind': 'analytics#webproperty',
          'level': 'STANDARD',
          'name': 'sitename_6',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
          'type': 'analytics#account'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'profileCount': 1,
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'updated': '2018-05-24T16:30:06.752Z',
          'websiteUrl': 'https://sitename_6'}]
          

        _webproperties = [WebProperty(raw, self) for raw in raw_properties]
        return addressable.List(_webproperties, indices=['id', 'name'], insensitive=True)
예제 #8
0
    def profiles(self):
        """
        A list of all profiles on this web property. You may
        select a specific profile using its name, its id
        or an index.

        ```python
        property.profiles[0]
        property.profiles['9234823']
        property.profiles['marketing profile']
        ```
        """
        #raw_profiles = self.account.service.management().profiles().list(
        #    accountId=self.account.id,
        #    webPropertyId=self.id).execute()['items']

        raw_profiles = [{'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2006-06-07T20:01:29.000Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'www.sitename_0',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXX',
          'siteSearchCategoryParameters': 'category',
          'siteSearchQueryParameters': 'q',
          'stripSiteSearchCategoryParameters': False,
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2019-11-04T15:45:15.079Z',
          'webPropertyId': 'UA-WEB_0-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2006-08-10T20:15:26.000Z',
          'currency': 'USD',
          'eCommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'Amex Monthly Gifts',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXX',
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2016-02-27T14:26:46.689Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2015-04-01T00:15:09.899Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'www.sitename_0 - TEST Environment',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'siteSearchQueryParameters': 'q',
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2018-01-05T22:06:51.692Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2015-04-01T00:15:34.040Z',
          'currency': 'USD',
          'defaultPage': 'Home.aspx',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'www.sitename_0 - UNFILTERED View',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'siteSearchCategoryParameters': 'category',
          'siteSearchQueryParameters': 'q',
          'stripSiteSearchCategoryParameters': False,
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2016-10-27T13:15:11.156Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2015-06-03T02:39:46.541Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'GIV3 Traffic Only',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2019-12-06T19:31:51.511Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2017-09-12T21:38:41.980Z',
          'currency': 'USD',
          'eCommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'sitename_0 - excluding internal traffic',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/New_York',
          'type': 'WEB',
          'updated': '2017-09-12T21:38:41.980Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-01-04T14:55:08.146Z',
          'currency': 'USD',
          'eCommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'www.sitename_0 - Donor Help & Charity Help View',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'siteSearchQueryParameters': 's',
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/New_York',
          'type': 'WEB',
          'updated': '2018-08-15T14:56:24.119Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': True,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-01-04T15:35:37.284Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'www.sitename_0 - Angela TEST Environment',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'siteSearchCategoryParameters': 'category',
          'siteSearchQueryParameters': 'q',
          'stripSiteSearchCategoryParameters': False,
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2018-06-07T14:23:17.083Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-06-22T18:31:50.420Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': True,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'Test View - CDN',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Los_Angeles',
          'type': 'WEB',
          'updated': '2018-08-10T16:48:09.300Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-08-10T16:46:29.030Z',
          'currency': 'CAD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'Events Only View',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2018-09-14T12:48:44.581Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'https://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-08-10T13:18:26.813Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': True,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'CDN Only View',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Los_Angeles',
          'type': 'WEB',
          'updated': '2019-02-07T22:57:13.804Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-08-10T18:50:34.929Z',
          'currency': 'USD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'P2P View',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2019-02-07T22:57:13.909Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'https://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-08-15T13:13:09.842Z',
          'currency': 'CAD',
          'eCommerceTracking': True,
          'enhancedECommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'Direct Site Only',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'siteSearchCategoryParameters': 'category',
          'siteSearchQueryParameters': 'q',
          'stripSiteSearchCategoryParameters': False,
          'stripSiteSearchQueryParameters': False,
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2019-11-04T15:45:29.600Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'},
        {'accountId': 'ACCT_1',
          'botFilteringEnabled': False,
          'childLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX/goals',
          'type': 'analytics#goals'},
          'created': '2018-09-07T15:36:03.285Z',
          'currency': 'CAD',
          'eCommerceTracking': False,
          'id': 'XXXXXX',
          'internalWebPropertyId': 'WEB_7',
          'kind': 'analytics#profile',
          'name': 'For Charities',
          'parentLink': {'href': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X',
          'type': 'analytics#webproperty'},
          'permissions': {'effective': ['COLLABORATE', 'READ_AND_ANALYZE']},
          'selfLink': 'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties/UA-XXXXXX-X/profiles/XXXXXXXXX',
          'timezone': 'America/Toronto',
          'type': 'WEB',
          'updated': '2019-06-06T15:29:47.740Z',
          'webPropertyId': 'UA-WEB_1-1',
          'websiteUrl': 'http://sitename_0'}]


        profiles = [Profile(raw, self) for raw in raw_profiles]
        return addressable.List(profiles, indices=['id', 'name'], insensitive=True)
예제 #9
0
def authenticate(credentials):
    client = credentials.authorize()
    service = discovery.build('analytics', 'v3', http=client)
    #raw_accounts = service.management().accounts().list().execute()['items']

    raw_accounts = [{
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2006-06-07T20:01:28.000Z',
        'id': 'XXXXXX',
        'kind': 'analytics#account',
        'name': 'sitename_11',
        'permissions': {
            'effective': ['COLLABORATE', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXX',
        'updated': '2019-07-02T18:00:31.573Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2014-02-13T03:15:18.155Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'sitename_10',
        'permissions': {
            'effective': []
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
        'updated': '2016-07-14T19:41:40.634Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2014-05-05T18:50:09.025Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'RankSense',
        'permissions': {
            'effective':
            ['COLLABORATE', 'EDIT', 'MANAGE_USERS', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX',
        'updated': '2017-02-25T17:20:39.203Z'
    }, {
        'childLink': {
            'href':
            'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXX/webproperties',
            'type': 'analytics#webproperties'
        },
        'created': '2017-05-05T15:40:21.336Z',
        'id': 'XXXXXXXX',
        'kind': 'analytics#account',
        'name': 'http://sitename_09/',
        'permissions': {
            'effective':
            ['COLLABORATE', 'EDIT', 'MANAGE_USERS', 'READ_AND_ANALYZE']
        },
        'selfLink':
        'https://www.googleapis.com/analytics/v3/management/accounts/XXXXXXXX',
        'updated': '2017-05-05T15:40:21.336Z'
    }]

    accounts = [
        account.Account(raw, service, credentials) for raw in raw_accounts
    ]
    return addressable.List(accounts, indices=['id', 'name'], insensitive=True)