Esempio n. 1
0
def dataset():
  if project.verbose:
    print('DATASET', project.id, project.task['dataset'])

  if project.task.get('delete', False):
    if project.verbose:
      print('DATASET DELETE')
    datasets_delete(
      project.task['auth'],
      project.id,
      project.task['dataset']
    )

  if project.verbose:
    print('DATASET CREATE')
  datasets_create(
    project.task['auth'],
    project.id,
    project.task['dataset']
  )

  if project.verbose:
    print('DATASET ACCESS')
  datasets_access(
    project.task['auth'],
    project.id,
    project.task['dataset'],
    emails=project.task.get('emails', []),
    groups=project.task.get('groups', [])
  )
Esempio n. 2
0
def dataset():
    if project.verbose: print("DATASET", project.id, project.task['dataset'])

    # create dataset
    datasets_create(project.task['auth'], project.id, project.task['dataset'])
    datasets_access(project.task['auth'],
                    project.id,
                    project.task['dataset'],
                    emails=project.task.get('emails', []),
                    groups=project.task.get('groups', []))
Esempio n. 3
0
def dataset(config, task):
    if config.verbose:
        print('DATASET', config.project, task['dataset'])

    if task.get('delete', False):
        if config.verbose:
            print('DATASET DELETE')
        # In order to fully delete a dataset, it needs to first have all tables
        # deleted, which is done with the delete_contents=True, and then the actual
        # dataset can be deleted, which is done with delete_contents=false.
        datasets_delete(config,
                        task['auth'],
                        config.project,
                        task['dataset'],
                        delete_contents=True)
        datasets_delete(config,
                        task['auth'],
                        config.project,
                        task['dataset'],
                        delete_contents=False)
    else:
        if task.get('clear', False):
            if config.project:
                print('DATASET CLEAR')
            datasets_delete(config,
                            task['auth'],
                            config.project,
                            task['dataset'],
                            delete_contents=True)

        if config.verbose:
            print('DATASET CREATE')
        datasets_create(config, task['auth'], config.project, task['dataset'])

        if config.verbose:
            print('DATASET ACCESS')
        datasets_access(config,
                        task['auth'],
                        config.project,
                        task['dataset'],
                        emails=task.get('emails', []),
                        groups=task.get('groups', []))
Esempio n. 4
0
def itp_audit_cm():
    account_id = project.task['account']
    # Read Advertiser Ids
    advertiser_ids = list(
        get_rows('service', project.task['read']['advertiser_ids']))
    is_superuser, profile_id = get_profile_for_api('user', account_id)

    datasets_create('user', project.id, project.task['dataset'])

    placements = {}
    campaignNames = {}
    siteNames = {}
    advertiserNames = {}

    for c in API_DCM('user', iterate=True,
                     internal=is_superuser).campaigns().list(
                         archived=False,
                         profileId=profile_id,
                         accountId=account_id,
                         advertiserIds=advertiser_ids
                         if advertiser_ids else None).execute():
        # only keep campaigns with end dates in the future or less than 90 days ago
        if ((date.fromisoformat(c['endDate']) - date.today()).days > -90):
            campaignNames[c['id']] = {
                'id': c['id'],
                'name': c['name'],
                'startDate': c['startDate'],
                'endDate': c['endDate']
            }

    validCampaignIds = [int(i) for i in campaignNames.keys()]

    for s in API_DCM('user', iterate=True, internal=is_superuser).sites().list(
            profileId=profile_id,
            accountId=account_id,
            campaignIds=validCampaignIds).execute():
        siteNames[s['id']] = s['name']

    for a in API_DCM('user', iterate=True,
                     internal=is_superuser).advertisers().list(
                         profileId=profile_id,
                         accountId=account_id,
                         ids=advertiser_ids[:500]
                         if advertiser_ids else None).execute():
        advertiserNames[a['id']] = a['name']

    if len(advertiser_ids) > 500:
        for a in API_DCM('user', iterate=True,
                         internal=is_superuser).advertisers().list(
                             profileId=profile_id,
                             accountId=account_id,
                             ids=advertiser_ids[500:]
                             if advertiser_ids else None).execute():
            advertiserNames[a['id']] = a['name']

    for p in API_DCM(
            'user', iterate=True, internal=is_superuser).placements().list(
                archived=False,
                profileId=profile_id,
                accountId=account_id,
                advertiserIds=advertiser_ids if advertiser_ids else None,
                campaignIds=validCampaignIds).execute():
        # exclude 1x1 tracking placements
        if not (p['size']['height'] == 1 and p['size']['width'] == 1):
            placements[p['id']] = {
                'id': p['id'],
                'name': p['name'],
                'advertiserId': p['advertiserId'],
                'advertiserName': advertiserNames[p['advertiserId']],
                'campaignId': p['campaignId'],
                'campaignName': campaignNames[p['campaignId']]['name'],
                'siteId': p['siteId'],
                'siteName': siteNames[p['siteId']],
                'adsTotal': 0,
                'adsNotImpacted': 0,
                'adsFrequencyCapped': 0,
                'adsAudienceSegmentation': 0,
                'adsAudienceListTargeting': 0,
                'adsDynamicCreative': 0,
                'adsPlatformBrowserTargeting': 0
            }

    for ad in API_DCM('user', iterate=True, internal=is_superuser).ads().list(
            type='AD_SERVING_STANDARD_AD',
            profileId=profile_id,
            accountId=account_id,
            campaignIds=validCampaignIds).execute():
        # only analyze standard, non-default priority ads that have been assigned 1+ placements and creatives
        if ad['deliverySchedule'][
                'priority'] != "AD_PRIORITY_16" and 'placementAssignments' in ad and 'creativeAssignments' in ad[
                    'creativeRotation']:
            hasDynamicCreative = False
            for creative in ad['creativeRotation']['creativeAssignments']:
                if 'richMediaExitOverrides' in creative:
                    hasDynamicCreative = True
                    break

            for p in ad['placementAssignments']:
                if p['placementId'] in placements:
                    knownPlacement = placements[p['placementId']]
                    knownPlacement['adsTotal'] += 1

                    if 'frequencyCap' in ad['deliverySchedule']:
                        knownPlacement['adsFrequencyCapped'] += 1
                    if 'audienceSegmentId' in ad:
                        knownPlacement['adsAudienceSegmentation'] += 1
                    if 'remarketingListExpression' in ad:
                        knownPlacement['adsAudienceListTargeting'] += 1
                    if 'technologyTargeting' in ad and (
                            'browsers' in ad['technologyTargeting']
                            or 'platformTypes' in ad['technologyTargeting']):
                        knownPlacement['adsPlatformBrowserTargeting'] += 1
                    if hasDynamicCreative:
                        knownPlacement['adsDynamicCreative'] += 1
                    if not 'frequencyCap' in ad[
                            'deliverySchedule'] and not 'audienceSegmentId' in ad and not 'remarketingListExpression' in ad:
                        knownPlacement['adsNotImpacted'] += 1

    write_data = []
    for p in placements.values():
        write_data.append([
            p['name'] + ' - ' + str(p['id']), p['id'], p['name'],
            p['advertiserName'] + ' - ' + str(p['advertiserId']),
            p['advertiserId'], p['advertiserName'],
            p['campaignName'] + ' - ' + str(p['campaignId']), p['campaignId'],
            p['campaignName'], p['siteId'], p['siteName'], p['adsTotal'],
            p['adsNotImpacted'], p['adsFrequencyCapped'],
            p['adsAudienceListTargeting'], p['adsAudienceSegmentation'],
            p['adsPlatformBrowserTargeting'], p['adsDynamicCreative']
        ])

    placements_out = {}
    placements_out["bigquery"] = {
        "dataset": project.task['dataset'],
        "table": CM_PLACEMENT_AUDIT_TABLE,
        "is_incremental_load": False,
        "datastudio": True,
        "schema": PLACEMENTS_SCHEMA,
        "skip_rows": 0
    }

    if placements: put_rows('service', placements_out, write_data)