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

Collect the domain on offer creation #954

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions adserver/migrations/0100_add_offer_domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.9 on 2024-12-02 23:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('adserver', '0099_link_advertiser_guide'),
]

operations = [
migrations.AddField(
model_name='click',
name='domain',
field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'),
),
migrations.AddField(
Copy link
Member

Choose a reason for hiding this comment

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

We might need to migrate this manually because of the issue with db_table.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We might. However, the migration file is correct. Worst case we can use sqlmigrate and alter it.

./manage.py sqlmigrate adserver 0100

model_name='offer',
name='domain',
field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'),
),
migrations.AddField(
model_name='view',
name='domain',
field=models.CharField(blank=True, max_length=10000, null=True, verbose_name='Domain'),
),
]
6 changes: 6 additions & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,7 @@ def _record_base(
parsed_ua = parse(user_agent)
country = get_client_country(request)
url = url or request.headers.get("referer")
domain = get_domain_from_url(url)

if (
model != Click
Expand All @@ -1799,6 +1800,7 @@ def _record_base(
client_id=client_id,
country=country,
url=url,
domain=domain,
paid_eligible=paid_eligible,
rotations=rotations,
# Derived user agent data
Expand Down Expand Up @@ -2589,6 +2591,10 @@ class AdBase(TimeStampedModel, IndestructibleModel):
country = CountryField(null=True)
url = models.CharField(_("Page URL"), max_length=10000, blank=True, null=True)

# Domain of the URL or None if the URL is not available
# Should not include http or any characters after the TLD
domain = models.CharField(_("Domain"), max_length=10000, blank=True, null=True)

# Fields derived from the user agent - these should not be user identifiable
browser_family = models.CharField(
_("Browser Family"), max_length=1000, blank=True, null=True, default=None
Expand Down
1 change: 1 addition & 0 deletions adserver/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def test_offer_ad(self):
self.assertEqual(offer.advertisement, self.ad1)
self.assertEqual(offer.div_id, div_id)
self.assertEqual(offer.url, url)
self.assertEqual(offer.domain, "example.com")
self.assertEqual(offer.ip, "1.1.0.0") # anonymized
self.assertEqual(offer.os_family, "Linux")
self.assertEqual(offer.browser_family, "Chrome")
Expand Down
Loading