googleads / googleads-python-lib

The Python client library for Google's Ads APIs
Apache License 2.0
682 stars 975 forks source link

Generating a report and getting different values #526

Closed Shaharbad closed 1 year ago

Shaharbad commented 1 year ago

Hey Everyone,

I'm trying to use the API to retrieve some data from my account. I managed to successfully generate the report and see the data, however, when comparing to the UI generated report i see different value for some dimensions, i also have a problem with how values are displayed.

The problems I see are:

  1. When using AD_EXCHANGE_LINE_ITEM_LEVEL_REVENUE I see 17403 which I know is not correct, on the UI I see $0.02.
  2. When using AD_EXCHANGE_LINE_ITEM_LEVEL_AVERAGE_ECPM I see the correct value but with no dot separator, I get 3480653, on the UI i see $3.48.
  3. When using AD_EXCHANGE_MATCH_RATE i see 0.1186, on the UI i see 11.86%.

How to make sure i see the same values on the API from the UI? Here's my code, I would appriciate any help:

#!/usr/bin/env python
#
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Runs a report with custom fields found in the line items of an order."""

import tempfile

# Import appropriate modules from the client library.
from googleads import ad_manager
from googleads import errors

CUSTOM_FIELD_ID = 'INSERT_CUSTOM_FIELD_ID'
CUSTOM_DIMENSION_KEY_ID = 'INSERT_CUSTOM_DIMENSION_KEY_ID'

def main(client, custom_field_id, custom_dimension_key_id):
  # Initialize a DataDownloader.
  report_downloader = client.GetDataDownloader(version='v202308')

  # Create report job.
  report_job = {
     'reportQuery': {
                'dimensions': [
                    'AD_UNIT_NAME',
                    'MOBILE_APP_NAME',
                    'MOBILE_APP_RESOLVED_ID',
                    'BROWSER_NAME'
                ],
                'adUnitView': 'FLAT',
                'columns': [
                    'AD_EXCHANGE_LINE_ITEM_LEVEL_IMPRESSIONS',
                    'AD_EXCHANGE_LINE_ITEM_LEVEL_REVENUE',
                    'AD_EXCHANGE_LINE_ITEM_LEVEL_AVERAGE_ECPM',
                    'AD_EXCHANGE_TOTAL_REQUESTS',
                    'AD_EXCHANGE_MATCH_RATE',
                ],
                'dimensionAttributes': [],
                'customFieldIds': [],
                'cmsMetadataKeyIds': [],
                'customDimensionKeyIds': [],
                'startDate': None,
                'endDate': None,
                'dateRangeType': 'YESTERDAY',
                'statement': None,
                'reportCurrency': 'USD',
            }
  }

  try:
    # Run the report and wait for it to finish.
    report_job_id = report_downloader.WaitForReport(report_job)
  except errors.AdManagerReportError as e:
    print('Failed to generate report. Error was: %s' % e)

  # Change to your preferred export format.
  export_format = 'CSV_DUMP'

  report_file = tempfile.NamedTemporaryFile(suffix='.csv.gz', delete=False)

  # Download report data.
  report_downloader.DownloadReportToFile(
      report_job_id, export_format, report_file)

  report_file.close()

  # Display results.
  print('Report job with id "%s" downloaded to:\n%s' % (
      report_job_id, report_file.name))

if __name__ == '__main__':
  # Initialize client object.
  ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage()
  main(ad_manager_client, CUSTOM_FIELD_ID, CUSTOM_DIMENSION_KEY_ID)
christopherseeley commented 1 year ago

When using the CSV_DUMP export format, monetary amounts are in micros (1 millionth of the base unit): 3,480,653 / 1,000,000 = $3.48 1,7403 / 1,000,000 = $0.017 rounded to $0.02

Percentages are in the rate value: 0.118 * 100 = 11.8%

If you want a human-readable format, you can use TSV or Excel format when exporting.

Shaharbad commented 1 year ago

When using the CSV_DUMP export format, monetary amounts are in micros (1 millionth of the base unit): 3,480,653 / 1,000,000 = $3.48 1,7403 / 1,000,000 = $0.017 rounded to $0.02

Percentages are in the rate value: 0.118 * 100 = 11.8%

If you want a human-readable format, you can use TSV or Excel format when exporting.

LEGEND! THANKS. could you please help me with filtering by Child Publisher network code? Here's my code:

    report_job = {
        'reportQuery': {
            'dimensions': dimensions,
            'adUnitView': 'FLAT',
            'columns': [
                'AD_EXCHANGE_LINE_ITEM_LEVEL_IMPRESSIONS',
                'AD_EXCHANGE_LINE_ITEM_LEVEL_REVENUE',
                'AD_EXCHANGE_LINE_ITEM_LEVEL_AVERAGE_ECPM',
                'AD_EXCHANGE_TOTAL_REQUESTS',
                'AD_EXCHANGE_MATCH_RATE',
            ],
            'dimensionAttributes': [],
            'customFieldIds': [],
            'cmsMetadataKeyIds': [],
            'customDimensionKeyIds': [],
            'startDate': start_date,
            'endDate': end_date,
            'dateRangeType': 'CUSTOM_DATE',
            'statement': None,
            'reportCurrency': 'USD',
        }
    }