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

Add support for niche targeting #865

Merged
merged 6 commits into from
Jun 26, 2024
Merged

Add support for niche targeting #865

merged 6 commits into from
Jun 26, 2024

Conversation

ericholscher
Copy link
Member

This adds support for setting a threshold of distance,
so flights outside of that distance are not shown.

This has a few limitations,
but could be a good first step for testing out a niche targeted flight,
and see what it's CTR looks like.

@ericholscher ericholscher requested a review from a team as a code owner April 3, 2024 23:40
Copy link
Collaborator

@davidfischer davidfischer left a comment

Choose a reason for hiding this comment

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

I think the INSTALLED_APPS check should be in the constructor. We can store a niche_weights=None in the constructor and only fill it out if there's any candidate flights with niche_targeting. We want to avoid doing this unless there's flights using the targeting. I'm really worried about this ballooning our time to ad.

This adds support for setting a threshold of distance,
so flights outside of that distance are not shown.

This has a few limitations,
but could be a good first step for testing out a niche targeted flight,
and see what it's CTR looks like.
Only run queries when a flight actually has niche_targeting set.
@ericholscher
Copy link
Member Author

@davidfischer I updated this to be a bit smarter, and only do any embedding queries if the flights have niche targeting, and there's an embedding for the publisher URL. I think this should be safe enough to ship, since we can disable it by just removing the targeting on a test flight, and it will only do the queries when the test flight is in the candidate flights 👍

Comment on lines +406 to +407
# Apply niche targeting only when any flight has it.
# This is to track whether we should do expensive distance queries.
Copy link
Member Author

Choose a reason for hiding this comment

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

I put this here so that we only run it when we hit an eligible flight that has niche targeting, so if eg. only house flights have it, it won't run if there's a paid ad.

adserver/models.py Outdated Show resolved Hide resolved
get_niche_weights,
) # noqa

self.niche_weights = get_niche_weights(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless I'm reading this wrong, won't this get the distance for every advertiser? It'd be really nice if the embedding was just cached on the flight (or directly linked with a FK so select_related just works). Then this check would just be a computation of getting the distance between the URL's embedding and the flight's embedding. Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, we have a few options here -- but in general a flight doesn't have a single embedding, since it can have multiple ads that each have their own. We can in theory "average" them in some fashion, but that isn't what we're doing currently.

In the future we can definitely change how this works a bit more, but for now I'm mostly just trying to reduce overall queries when we aren't doing targeting, so we can start testing it in prod and see how slow it is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright. I think we'll have to calculate a flight embedding eventually but we can at least get a start with this.

adserver/models.py Outdated Show resolved Hide resolved
adserver/models.py Outdated Show resolved Hide resolved
Co-authored-by: David Fischer <david@readthedocs.org>
@ericholscher ericholscher merged commit cb3eb98 into main Jun 26, 2024
1 check passed
@ericholscher ericholscher deleted the niche-targeting branch June 26, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants