Skip to content

Commit 260a023

Browse files
authored
Merge pull request #1008 from readthedocs/davidfischer/offer-date
Fix view/click date to date to offer
2 parents 8dd059b + 3b7345f commit 260a023

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

adserver/models.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1713,14 +1713,20 @@ def generate_slug(cls, name):
17131713
def advertiser(self):
17141714
return self.flight.campaign.advertiser
17151715

1716-
def incr(self, impression_type, publisher):
1716+
def incr(self, impression_type, publisher, offer=None):
17171717
"""
17181718
Add to the number of times this action has been performed, stored in the DB.
17191719
17201720
TODO: Refactor this method, moving it off the Advertisement class since it can be called
17211721
without an advertisement when we have a Decision and no Offer.
17221722
"""
1723-
day = get_ad_day().date()
1723+
if offer:
1724+
# For views/clicks, use the date of the existing offer
1725+
day = offer.date.date()
1726+
else:
1727+
# If we don't have an offer (the offer is about to be created),
1728+
# we use the current date
1729+
day = get_ad_day().date()
17241730

17251731
if isinstance(impression_type, str):
17261732
impression_types = (impression_type,)
@@ -1834,7 +1840,7 @@ def track_impression(self, request, impression_type, publisher, offer):
18341840

18351841
def track_click(self, request, publisher, offer):
18361842
"""Store click data in the DB."""
1837-
self.incr(impression_type=CLICKS, publisher=publisher)
1843+
self.incr(impression_type=CLICKS, publisher=publisher, offer=offer)
18381844
return self._record_base(
18391845
request=request,
18401846
model=Click,
@@ -1856,7 +1862,7 @@ def track_view(self, request, publisher, offer):
18561862
For a large scale ad server, writing a database record per ad view
18571863
is not feasible
18581864
"""
1859-
self.incr(impression_type=VIEWS, publisher=publisher)
1865+
self.incr(impression_type=VIEWS, publisher=publisher, offer=offer)
18601866

18611867
if request.GET.get("uplift"):
18621868
# Don't overwrite Offer object here, since it might have changed prior to our writing
@@ -1916,7 +1922,6 @@ def offer_ad(
19161922
"""
19171923
ad_type = AdType.objects.filter(slug=ad_type_slug).first()
19181924

1919-
self.incr(impression_type=(OFFERS, DECISIONS), publisher=publisher)
19201925
offer = self._record_base(
19211926
request=request,
19221927
model=Offer,
@@ -1928,6 +1933,7 @@ def offer_ad(
19281933
paid_eligible=paid_eligible,
19291934
rotations=rotations,
19301935
)
1936+
self.incr(impression_type=(OFFERS, DECISIONS), publisher=publisher, offer=offer)
19311937

19321938
if forced and self.flight.campaign.campaign_type == PAID_CAMPAIGN:
19331939
# Ad offers forced to a specific ad or campaign should never be billed.
@@ -2007,8 +2013,7 @@ def record_null_offer(
20072013
Without this, when we don't offer an ad and a user doesn't have house ads on,
20082014
we don't have any way to track how many requests for an ad there have been.
20092015
"""
2010-
cls.incr(self=None, impression_type=DECISIONS, publisher=publisher)
2011-
cls._record_base(
2016+
offer = cls._record_base(
20122017
self=None,
20132018
request=request,
20142019
model=Offer,
@@ -2019,6 +2024,7 @@ def record_null_offer(
20192024
ad_type_slug=ad_type_slug,
20202025
paid_eligible=paid_eligible,
20212026
)
2027+
cls.incr(self=None, impression_type=DECISIONS, publisher=publisher, offer=offer)
20222028

20232029
def is_valid_offer(self, impression_type, offer):
20242030
"""

0 commit comments

Comments
 (0)