Skip to content

Commit

Permalink
Merge pull request #833 from readthedocs/davidfischer/publisher-reven…
Browse files Browse the repository at this point in the history
…ue-ecpm

Add publisher eCPM to report table
  • Loading branch information
ericholscher committed Feb 21, 2024
2 parents 198834e + 0821b16 commit 207de18
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions adserver/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ def generate(self):
results[index]["revenue_share"] = results[index]["revenue"] * (
applied_rev_share / 100.0
)
results[index]["revenue_share_ecpm"] = calculate_ecpm(
results[index]["revenue_share"], results[index]["views"]
)
results[index]["our_revenue"] = (
results[index]["revenue"] - results[index]["revenue_share"]
)
Expand Down Expand Up @@ -301,6 +304,9 @@ def calculate_totals(self):
self.total["revenue_share"] = sum(
result["revenue_share"] for result in self.results
)
self.total["revenue_share_ecpm"] = calculate_ecpm(
self.total["revenue_share"], self.total["views"]
)
self.total["our_revenue"] = self.total["revenue"] - self.total["revenue_share"]
self.total["ctr"] = calculate_ctr(self.total["clicks"], self.total["views"])
self.total["ecpm"] = calculate_ecpm(self.total["revenue"], self.total["views"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<th class="text-right"><strong>{% blocktrans %}<abbr title="Click through rate">CTR</abbr>{% endblocktrans %}</strong></th>
<th class="text-right"><strong>{% blocktrans %}<abbr title="% of traffic that viewed the ad">View Rate</abbr>{% endblocktrans %}</strong></th>
{% if publisher.saas %}
<th class="text-right"><strong>{% blocktrans %}<abbr title="Billable API requests">API Requests</abbr>{% endblocktrans %}</strong></th>
<th class="text-right"><strong>{% blocktrans %}<abbr title="Billable API requests">API Requests</abbr>{% endblocktrans %}</strong></th>
{% else %}
<th class="text-right"><strong>{% trans 'Revenue' %}</strong></th>
<th class="text-right"><strong>{% blocktrans %}<abbr title="Effective publisher revenue per thousand impressions">eCPM</abbr>{% endblocktrans %}</strong></th>
<th class="text-right"><strong>{% trans 'Revenue' %}</strong></th>
{% endif %}
{% if "adserver.staff_publisher_fields" in perms %}
<th class="text-right staff-only"><strong>{% trans 'Our&nbsp;Rev' %}</strong></th>
Expand All @@ -34,6 +35,7 @@
{% if publisher.saas %}
<td class="text-right">{{ result.decisions|intcomma }}</td>
{% else %}
<td class="text-right">${{ result.revenue_share_ecpm|floatformat:2|intcomma }}</td>
<td class="text-right">${{ result.revenue_share|floatformat:2|intcomma }}</td>
{% endif %}
{% if "adserver.staff_publisher_fields" in perms %}
Expand All @@ -54,6 +56,7 @@
{% if publisher.saas %}
<td class="text-right"><strong>{{ report.total.decisions|intcomma }}</strong></td>
{% else %}
<td class="text-right"><strong>${{ report.total.revenue_share_ecpm|floatformat:2|intcomma }}</strong></td>
<td class="text-right"><strong>${{ report.total.revenue_share|floatformat:2|intcomma }}</strong></td>
{% endif %}
{% if "adserver.staff_publisher_fields" in perms %}
Expand Down
4 changes: 2 additions & 2 deletions adserver/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def test_publisher_report_contents(self):
self.assertContains(response, "CSV Export")

# Check staff fields not present since the permission wasn't configured
self.assertNotContains(response, "eCPM")
self.assertNotContains(response, "Fill Rate")

# Add the permission
self.staff_user.user_permissions.add(
Expand All @@ -567,7 +567,7 @@ def test_publisher_report_contents(self):
)
)
response = self.client.get(url)
self.assertContains(response, "eCPM")
self.assertContains(response, "Fill Rate")

def test_publisher_placement_report_contents(self):
self.client.force_login(self.staff_user)
Expand Down

0 comments on commit 207de18

Please sign in to comment.