Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RON support and Bidder Code Params #52

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

pbrisson
Copy link
Contributor

Fixes #16 - used suggested parameter DFP_ALLOW_NO_INVENTORY_TARGETING when no DFP_TARGETED_PLACEMENT_NAMES is provided.

I also needed Bidders' Params to be used when sending all bids to the ad server was required (see: http://prebid.org/dev-docs/bidders.html and http://prebid.org/adops/send-all-bids-adops.html), so I added the PREBID_BIDDER_PARAMS parameter for that purpose. It's important to note that when that parameter is used, hb_bidder is not matched against Bidder Code.

I also put the base to retrieve ad units when required, although it was finally not used (preferred to extract root ad unit id directly from network). But that could eventually be used to fix #17 !

@pbrisson
Copy link
Contributor Author

Just added another option so it's possible to make line item/creative associations in batch. Was using 450 line items and 10 creatives, which ended up requiring 4500 associations - this unfortunately times out on DFP API.

Named the option "DFP_ASSOCIATIONS_BATCH".

Copy link
Owner

@kmjennison kmjennison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing this PR! Overall, it looks great, and I expect it'll helpful to a lot of people. The requested changes are mostly just related to code cleanliness and test coverage. LMK if you won't have the time to address them.

import settings
import time
import suds
from pprint import pprint
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused pprint

@@ -80,11 +80,14 @@ Setting | Description | Default
`DFP_USE_EXISTING_ORDER_IF_EXISTS` | Whether we should modify an existing order if one already exists with name `DFP_ORDER_NAME` | `False`
`DFP_NUM_CREATIVES_PER_LINE_ITEM` | The number of duplicate creatives to attach to each line item. Due to [DFP limitations](https://support.google.com/dfp_sb/answer/82245?hl=en), this should be equal to or greater than the number of ad units you serve on a given page. | the length of setting `DFP_TARGETED_PLACEMENT_NAMES`
`DFP_CURRENCY_CODE` | The currency to use in line items. | `'USD'`
`DFP_ALLOW_NO_INVENTORY_TARGETING` | If no placement should be used, for example for a run of network. If True, DFP_TARGETED_PLACEMENT_NAMES still need to be set to an empty array. | `False`
`DFP_ASSOCIATIONS_BATCH` | Determine number of line item/creative associations to be created in one batch. | the number of line items to be created multiplied by `DFP_NUM_CREATIVES_PER_LINE_ITEM`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a setting. We can simply always use batch updates.

@@ -80,11 +80,14 @@ Setting | Description | Default
`DFP_USE_EXISTING_ORDER_IF_EXISTS` | Whether we should modify an existing order if one already exists with name `DFP_ORDER_NAME` | `False`
`DFP_NUM_CREATIVES_PER_LINE_ITEM` | The number of duplicate creatives to attach to each line item. Due to [DFP limitations](https://support.google.com/dfp_sb/answer/82245?hl=en), this should be equal to or greater than the number of ad units you serve on a given page. | the length of setting `DFP_TARGETED_PLACEMENT_NAMES`
`DFP_CURRENCY_CODE` | The currency to use in line items. | `'USD'`
`DFP_ALLOW_NO_INVENTORY_TARGETING` | If no placement should be used, for example for a run of network. If True, DFP_TARGETED_PLACEMENT_NAMES still need to be set to an empty array. | `False`
`DFP_ASSOCIATIONS_BATCH` | Determine number of line item/creative associations to be created in one batch. | the number of line items to be created multiplied by `DFP_NUM_CREATIVES_PER_LINE_ITEM`
`PREBID_BIDDER_PARAMS` | Whether DFP targeting keys should be created following Bidders' Params structure. This is used when it's required to send all bids to the ad server. | `False`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming this setting to PREBID_SEND_ALL_BIDS? I think that's a little clearer.


## Limitations

* 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](../../issues/18))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the "and price bucket targeting key (hb_pb) are not customizable" because this PR still doesn't allow naming hb_pb to anything arbitrary.

u'Created {0} line item <> creative associations.'.format(len(licas)))
associations_batch = getattr(settings, 'DFP_ASSOCIATIONS_BATCH', None)

if not associations_batch is None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, let's just always use batch uploads here. Do you know if DFP has any batch size limits? I didn't see any. Hardcoding something like 20 or 50 items seems reasonable (whatever you found works for you).

# Optional
# Determine if line items and creative should be associated in batch.
# Useful to avoid timeouts if many of them have to be created.
# DFP_ASSOCIATIONS_BATCH = 50
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, let's not add this setting.

# In the case where no inventory is being used, make sure at least one
# creative is created
if not num_creatives > 0:
num_creatives = 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's actually raise an exception (earlier in the settings validation where we first call getattr) and force the user to set a number in this case. That's better than having their ads not show because they have too few creatives (see #13 (comment)).

additional_keys = ''

if bidder_params is True:
hb_pb_key += '_' + bidder_code
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted elsewhere, please move this logic into a standalone module and reuse it elsewhere.

'operator': 'IS',
'valueIds': [111111],
'valueIds': [222222],
'xsi_type': 'CustomCriteria'
}
],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another test for run-of-network settings.

prices_summary=prices_summary,
bidder_code=bidder_code,
placements=placements,
sizes=sizes,
name_start_format=color.BOLD,
format_end=color.END,
value_start_format=color.BLUE,
additional_keys=additional_keys
))

ok = input('Is this correct? (y/n)\n')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a couple tests to test_add_new_prebid_partner.py to test the validations of the new settings?

@betancourtl
Copy link

Would love to see this merged. I would be willing to make the changes but python is not my main language.

Whats holding this back? general cleanup and tests?

@pbrisson
Copy link
Contributor Author

Apologies - just really busy with work and most of changes requests are, as @kmjennison mentions, for code cleanliness and tests coverage. I'm still using changes suggested in this PR in a production environment, almost daily. Might proceed as some point, but my schedule is just too hectic for now...

@betancourtl
Copy link

Alright well, thx for adding this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants