Skip to content

Commit

Permalink
Merge pull request #837 from readthedocs/davidfischer/ignore-publishe…
Browse files Browse the repository at this point in the history
…r-mobile-traffic

Ignore publisher mobile traffic option
  • Loading branch information
davidfischer committed Mar 6, 2024
2 parents 78f7d14 + 81cc047 commit 8e6f6b5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions adserver/decisionengine/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ def should_display_ads(self):
)
return False

# If this publisher's mobile traffic is ignored, don't serve anything
if self.publisher.ignore_mobile_traffic and self.user_agent.is_mobile:
log.info(
"Publisher mobile traffic is ignored. publisher=%s", self.publisher
)
return False

return True


Expand Down
29 changes: 29 additions & 0 deletions adserver/migrations/0093_publisher_ignore_mobile_traffic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.4 on 2024-03-01 00:18
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("adserver", "0092_payout_method_github_sponsors"),
]

operations = [
migrations.AddField(
model_name="historicalpublisher",
name="ignore_mobile_traffic",
field=models.BooleanField(
default=False,
help_text="If true, no ads will be served to this publisher's mobile users",
),
),
migrations.AddField(
model_name="publisher",
name="ignore_mobile_traffic",
field=models.BooleanField(
default=False,
help_text="If true, no ads will be served to this publisher's mobile users",
),
),
]
7 changes: 7 additions & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ class Publisher(TimeStampedModel, IndestructibleModel):
help_text=_("Completely disable this publisher"),
)

# Use this for publishers with unoptimized/unsupported mobile placements
# This essentially means the network is "not buying" the publisher's mobile traffic
ignore_mobile_traffic = models.BooleanField(
default=False,
help_text=_("If true, no ads will be served to this publisher's mobile users"),
)

saas = models.BooleanField(
default=False,
help_text=_(
Expand Down
2 changes: 2 additions & 0 deletions adserver/templates/adserver/includes/publisher-notices.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<div class="alert alert-warning" role="alert">{% blocktrans %}Your publisher account is disabled. If this is in error, please <a href="{{ support_url }}">contact us</a>.{% endblocktrans %}</div>
{% elif publisher and not publisher.allow_paid_campaigns and not publisher.saas %}
<div class="alert alert-warning" role="alert">{% blocktrans %}Your publisher account is not approved for paid campaigns. When you are ready for us to review your integration, please <a href="{{ support_url }}">contact us</a>.{% endblocktrans %}</div>
{% elif publisher and publisher.ignore_mobile_traffic %}
<div class="alert alert-info" role="alert">{% blocktrans %}Ads are not displayed on your site to mobile users. Please <a href="{{ support_url }}">contact support</a> with any questions.{% endblocktrans %}</div>
{% endif %}
23 changes: 23 additions & 0 deletions adserver/tests/test_decision_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,29 @@ def test_flight_mobile_targeting(self):
ad, _ = self.backend.get_ad_and_placement()
self.assertIsNone(ad)

def test_exclude_publisher_mobile_traffic(self):
self.publisher.ignore_mobile_traffic = True
self.publisher.save()

# Set a non-mobile UA
self.backend.user_agent = parse(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
)

ad, _ = self.backend.get_ad_and_placement()
self.assertIsNotNone(ad)

# Setup a mobile user agent
self.backend.user_agent = parse(
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) "
"AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"
)

# No ad should be served since the publisher's mobile traffic is excluded from ads
ad, _ = self.backend.get_ad_and_placement()
self.assertIsNone(ad)

def test_flight_days_targeting(self):
# Remove existing flights
for flight in Flight.objects.all():
Expand Down

0 comments on commit 8e6f6b5

Please sign in to comment.