/dfp-prebid-setup

A tool to create DFP line items for Prebid.js header bidding in batches (forked from https://github.com/kmjennison/dfp-prebid-setup)

Primary LanguagePythonMIT LicenseMIT

Build Status

Line item creator for Google Ad Manager

An automated line item generator for Google Ad Manager (previously DFP)
Clone this repository and follow 3 major steps to create 425 line items in Google Ad Manager for AIRIS.

  1. Creat Google Credentials
  2. Creating a Placement in Google Ad Manager
  3. Input Configuration and run the code

Create Google Credentials

Create a Sercvice account key

  1. Go to the Google Developers Console Credentials page.
  2. On the Credentials page, select Create credentials, then select Service account key. GDCC_createCredentials
  3. Click the dropdown menu under Service account. GDCC_CreateServiceAccount
  4. Select New service account GDCC_NewServiceAccount
  5. Set up the service account name, leave the role blank, and select JSON key type. GDCC_SetUpNewServiceAccount
  6. Click Create to download a file containing a .json private key. Click CREATE WITHOUT ROLE when you see the dialogue. GDCC_CreateWithoutRole
  7. Rename the private key ([something].json) to key.json and move it to the root of this repository

Set up Service Account in Google Ad manager

  1. Enable API access to Google Ad Manager
    • Sign into your Google Ad Manager. You must have admin rights.
    • In the Admin section, select Global settings
    • Ensure that API access is enabled.
    • Click the Add a service account user button. GAM_AddAServiceAccountUser
    • Set up the service account user.
      • Use the service account email for the Google developer credentials you created above.
      • Set the role to "Trafficker".
      • Click Save. GAM_SetUpServiceAccount

Create a Placement in Google Ad Manager

  1. Create a Placement in Google Ad manager
    • In the Inventory section, select Ad units, select Placements tab, and click New placement button. GAM_Placement
    • Give the new placement a name. In the Inventory section, select all the ad units that are specified in the configuration csv file that you previously uploaded to AIRIS GAM_SetUpNewPlacement
    • Click Save.

Set Up Configuration and Run the Code

Set Up google.yaml in the repository

  1. From the root of the repository, set up python3 development environment.
  2. Run pip install -r requirements.txt.
  3. Make a copy of googleads.example.yaml and name it googleads.yaml.
  4. In googleads.yaml, set the required fields:
    • application_name is the name of the Google project you created when creating the service account credentials. It should appear in the top-left of the credentials page.
    • network_code is your GAM network number; e.g., for https://admanager.google.com/12398712#delivery, the network code is 12398712.

Verify Setup

Let's try it out! From the top level directory, run

python -m dfp.get_orders

and you should see all of the orders in your GAM account.

If you see the error message, ValueError: unknown locale: UTF-8, please run

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

and try again.

Set up local_settings.py

  1. Make a copy of local_settings.example.py and name it local_settings.py.
  2. Modify the following settings in local_settings.py:
Setting Description Type
DFP_ORDER_NAME What you want to call this order string (e.g., 'dfpordername')
DFP_USER_EMAIL_ADDRESS The service account email for the Google developer credentials you created above string (e.g., 'email@email.com')
DFP_ADVERTISER_NAME The service account name for the Google developer credentials you created above string (e.g., 'advertisername')
DFP_TARGETED_PLACEMENT_NAMES The names of GAM placements you created above array of strings (e.g., ['placementname'])
DFP_PLACEMENT_SIZES The creative sizes of all ad units specified in the configuration csv you uploaded array of objects (e.g., [{'width': '728', 'height': '90'}])
DFP_CURRENCY_CODE New Taiwan Dollar: ‘TWD'
United States Dollar: ‘USD’
Japanese Yen: ‘JPY’
The currency settings is in the Global Settings of Google Ad Manager
string
DFP_NUM_CREATIVES_PER_LINE_ITEM Maximum Ad Units on any given webpage of your website number

Run:

python -m tasks.add_new_prebid_partner

After running successfully, you will see this message

Happy bidding!

Then, approve the order in Google Ad Manager. GAM_Approve

Note: GAM might show a "Needs creatives" warning on the order for ~15 minutes after order creation. Typically, the warning is incorrect and will disappear on its own.

Limitations

  • This tool does not currently support run-of-network line items (see #16). You must target line items to placements, ad units, or both.
  • Currently, the names of the bidder code targeting key (hb_bidder) and price bucket targeting key (hb_pb) are not customizable. The hb_bidder targeting key is currently required (see #18)
  • This tool does not support additional line item targeting beyond placement, ad units, hb_bidder, and hb_pb values.
  • This tool does not modify existing orders or line items, it only creates them. If you need to make a change to an order, it's easiest to archive the existing order and recreate it.

Please consider contributing to make the tool more flexible.