@@ -1713,14 +1713,20 @@ def generate_slug(cls, name):
1713
1713
def advertiser (self ):
1714
1714
return self .flight .campaign .advertiser
1715
1715
1716
- def incr (self , impression_type , publisher ):
1716
+ def incr (self , impression_type , publisher , offer = None ):
1717
1717
"""
1718
1718
Add to the number of times this action has been performed, stored in the DB.
1719
1719
1720
1720
TODO: Refactor this method, moving it off the Advertisement class since it can be called
1721
1721
without an advertisement when we have a Decision and no Offer.
1722
1722
"""
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 ()
1724
1730
1725
1731
if isinstance (impression_type , str ):
1726
1732
impression_types = (impression_type ,)
@@ -1834,7 +1840,7 @@ def track_impression(self, request, impression_type, publisher, offer):
1834
1840
1835
1841
def track_click (self , request , publisher , offer ):
1836
1842
"""Store click data in the DB."""
1837
- self .incr (impression_type = CLICKS , publisher = publisher )
1843
+ self .incr (impression_type = CLICKS , publisher = publisher , offer = offer )
1838
1844
return self ._record_base (
1839
1845
request = request ,
1840
1846
model = Click ,
@@ -1856,7 +1862,7 @@ def track_view(self, request, publisher, offer):
1856
1862
For a large scale ad server, writing a database record per ad view
1857
1863
is not feasible
1858
1864
"""
1859
- self .incr (impression_type = VIEWS , publisher = publisher )
1865
+ self .incr (impression_type = VIEWS , publisher = publisher , offer = offer )
1860
1866
1861
1867
if request .GET .get ("uplift" ):
1862
1868
# Don't overwrite Offer object here, since it might have changed prior to our writing
@@ -1916,7 +1922,6 @@ def offer_ad(
1916
1922
"""
1917
1923
ad_type = AdType .objects .filter (slug = ad_type_slug ).first ()
1918
1924
1919
- self .incr (impression_type = (OFFERS , DECISIONS ), publisher = publisher )
1920
1925
offer = self ._record_base (
1921
1926
request = request ,
1922
1927
model = Offer ,
@@ -1928,6 +1933,7 @@ def offer_ad(
1928
1933
paid_eligible = paid_eligible ,
1929
1934
rotations = rotations ,
1930
1935
)
1936
+ self .incr (impression_type = (OFFERS , DECISIONS ), publisher = publisher , offer = offer )
1931
1937
1932
1938
if forced and self .flight .campaign .campaign_type == PAID_CAMPAIGN :
1933
1939
# Ad offers forced to a specific ad or campaign should never be billed.
@@ -2007,8 +2013,7 @@ def record_null_offer(
2007
2013
Without this, when we don't offer an ad and a user doesn't have house ads on,
2008
2014
we don't have any way to track how many requests for an ad there have been.
2009
2015
"""
2010
- cls .incr (self = None , impression_type = DECISIONS , publisher = publisher )
2011
- cls ._record_base (
2016
+ offer = cls ._record_base (
2012
2017
self = None ,
2013
2018
request = request ,
2014
2019
model = Offer ,
@@ -2019,6 +2024,7 @@ def record_null_offer(
2019
2024
ad_type_slug = ad_type_slug ,
2020
2025
paid_eligible = paid_eligible ,
2021
2026
)
2027
+ cls .incr (self = None , impression_type = DECISIONS , publisher = publisher , offer = offer )
2022
2028
2023
2029
def is_valid_offer (self , impression_type , offer ):
2024
2030
"""
0 commit comments