The Python-based command-line Line Item Tool automates line item creation for OpenWrap. You define the advertiser, placements or ad units, and OpenWrap settings. The Line Item Tool uses your definitions to create an order with one line item per price level, attach creatives, then set placements and OpenWrap key-value targeting.
The goal for the Line Item Tool is to provide a codebase that Solutions Engineers can easily modify to let publishers with unique line item needs, easily code custom line item updates. This Line Item Tool update is a modified version of the open-source dfp-prebid-setup line item tool. Anyone who knows how to code in Python can extend/customize the tool's code to handle their custom requirements.
This guide summarizes instructions from a variety of sources to help you get up-to-speed quickly accessing Google Ad Manager, meeting the Python code requirements, and using the Line Item Tool.
DFP is now called, Google Ad Manager (GAM):
When you see DFP mentioned in this guide, remember that it is referring to GAM.
The first task is to create Google credentials to programmatically access the publisher's GAM account, and then provide access to those credentials in the GAM account:
- If you haven't done so yet, sign up for a GAM account.
- Create Google developer credentials:
- Go to the Google Developers Console Credentials page.
- On the Credentials page, select Create credentials, then Service account key.
- Select New service account, and select JSON key type. You can leave role blank.
- Use Create to download a file containing the
- Enable API access to GAM
- Sign into your GAM account—you must have admin rights.
- In the Admin section, select Global Settings.
- Ensure that API access is turned on.
- Press the Add a service account user button, then:
- Enter the service account email for the Google developer credentials you created above.
- Set the role to Administrator.
- Save your settings.
Set up the tool on your local machine using docker
- Clone the git repo
- git clone, https://github.com/PubMatic-OpenWrap/dfp-prebid-setup.git
- cd dfp-prebid-setup
- Rename the Google credentials key you previously downloaded (
key.json, then move it to the root of this repository.
- Build and run a docker container:
- Install Docker (if not already installed).
- Build the docker:
docker build -t openwrap-dfp .
- Run the container:
docker run -tid openwrap-dfp (returns a container id that you will use in the next step)
- Execute an interactive bash shell on the container where you can run the tool:
docker exec -t -i <container_id> /bin/sh
- Make a copy of
googleads.example.yaml, then rename it,
googleads.yaml, set these required fields:
application_name— the Google project you named while creating GAM credentials above. It should appear in the top-left of the credentials page.
network_code— your GAM network number; for example, in the url:
, the network code is
path_to_private_key_file— the path to the JSON file downloaded while creating google credentials.
Here is the sample content for
- Make a copy of
- Verify your setup
To test your set up, from the top-level directory, run:
If successful, it returns all the orders in your GAM account.
python -m dfp.get_orders
- Create line items for OpenWrap
- Edit the
settings.pyfor the line items, you want to create.
- Read the instructions in the README for config values.
- For the price buckets file, use the same file template used by the existing line item tool: LineItem.csv
Important…Ignore the Order Name and Advertiser columns are in the CSV file. Specify those settings in,
- Execute the tool:
python -m tasks.add_new_openwrap_partner
- Edit the
For example, if you want to create line items for Display platform with a safe-frame option, the minimum settings you'll need in the
settings.py file resembles the following:
The output after running,
tasks.add_new_openwrap_partner with the above
settings.py will resemble the following:
The new Line Item Tool supports the following functionality that the previous version does not:
- Create line items in any currency.
- An unlimited number of custom targeting parameters.
Contribute to the tool
Anyone proficient in Python programming can contribute to extending the capabilities of the Line Item Tool. If you would like to contribute, fork this repo, commit your changes, and open a pull request.
The code is divided mainly into three main directories:
- tasks — contains the methods to add new tasks that will be related to a line item or GAM account, like creating OpenWrap line items.
- dfp — contains all GAM-related code to get orders, create line items, and so on. Internally methods defined in
tasksfolder call methods defined in this directory; it contains all functions needed to execute basic GAM tasks.
- tests, tests_integration — contains all unit tests and the related utilities.
For example, to update the rate of a line item, you can add the following two files:
tasksfolder. It accepts/reads the line item ID, the new rate, and calls the function defined in dfp directory to update line items:
dfpfolder. It gets the line item from the GAM account, forms the updated line item config, and calls the GAM line item service to update the line item.
For GAM-related code, see the sample code available in, https://github.com/googleads/googleads-python-lib/tree/master/examples/ad_manager/v202102. For line item updates see, Update Line Item Example.
Using the Line Item Tool's modular framework, you can support a wide range of custom requirements and also contribute to extending and improving this tool.