Google DV360 – Audience and Geography Targeting at Scale with Python

Google DV360 – Audience and Geography Targeting at Scale with Python

The Google DV360 platform is making great strides in its feature set and usability. The platform allows many bulk actions to be performed via the user interface, however, targeting unique audiences and geographies is still a very manual process. This code aims is to increase efficiency when targeting multiple unique list combinations or unique geographies. These methods are particularly applicable when testing audience lists and when localizing by geographies. The full code can be found on GitHub.

This code operates in 2 steps. The first being fetching default SDF templates that you pre specify in a dummy insertion order. The second step creates new SDFs using your template in addition to a modifier file where you will specify line item names and audience list ids or geography ids. In order for the first step to work you must create a Google service account and add it as a user to DV360. You will receive a json key file containing the credentials of your service account.

With your service account and key file in order we can now begin discussing the code. The following packages and modules are needed to to run this code:

We define a few helper functions to streamline operations. The inj1 and ind1 functions are used for adding an additional ‘AND’ statements to audience targeting in your template. The fmt1 and fmt2 functions are used for formatting audience and geography cells (respectively) to be compliant within SDF file. StartDate and EndDate functions specify start and end dates to make upload easier. These dates can later be changed in bulk via the UI. The function empty1 is merely a convenience function that returns an empty string.

The GetTemplate function retrieves all line items from your template insertion order and returns a buffer to the line items in SDF format typed as a string. Be sure to provide your keyfile and the DV360 id of your template insertion order to this function.

The WriteSDF function will create a new SDF with new audience targeting or geography targeting using your template and modifier file. Create your modifier file as a csv with columns for line item names, and audience_list_id or geography_id corresponding to each new unique line item that you would like to make. Be sure to inspect and specify the the template row that you’d like to use as your template. The option to specify a template row allows one select a single template row while still having multiple template variants available for use.

Finally, specify your variables and call the functions.

Leave a Reply

Your email address will not be published. Required fields are marked *