Skip to content

Commit

Permalink
Per ad per day advertiser table/export
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfischer committed Oct 2, 2024
1 parent c8cd6f2 commit 15629d7
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
37 changes: 37 additions & 0 deletions adserver/templates/adserver/reports/advertiser-per-ad.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "adserver/reports/advertiser.html" %}
{% load humanize %}
{% load i18n %}
{% load metabase %}


{% block title %}{% trans 'Advertiser Per Ad Per Day Report' %} - {{ advertiser }}{% endblock %}


{% block heading %}
{% blocktrans %}Advertiser Per Ad Per Day Report for {{ advertiser }}{% endblocktrans %}
{% endblock heading %}

{% block breadcrumbs %}
{{ block.super }}
<li class="breadcrumb-item active">{% trans 'Per Ad Per Day Report' %}</li>
{% endblock breadcrumbs %}


{% block explainer %}
<section class="mb-5">
<h3>{% trans 'About this report' %}</h3>
<p>{% trans 'This report shows a table of data with one entry for each ad for every day that ad is shown. The data can be exported to CSV/Excel for further analysis with the icon at the bottom right.' %}</p>
</section>
{% endblock explainer %}


{% block report %}{% endblock report %}


{% block summary %}
<div class="row mb-5">
<div class="col min-vh-100">
{% metabase_question_embed metabase_advertiser_per_ad advertiser_slug=advertiser.slug start_date=start_date end_date=end_date %}
</div>
</div>
{% endblock summary %}
5 changes: 5 additions & 0 deletions adserver/templates/adserver/reports/advertiser.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ <h2 class="col-md-8">{% trans 'Total results for all ads across all flights' %}<

{% if export_url %}
<aside class="mb-3 col-md-4 text-right">
<a href="{% url 'advertiser_per_ad_report' advertiser.slug %}" class="btn btn-sm btn-outline-secondary" role="button" aria-pressed="true">
<span class="fa fa-bar-chart mr-1" aria-hidden="true"></span>
<span>Per Ad Breakdown</span>
</a>

<a href="{{ export_url }}" class="btn btn-sm btn-outline-secondary" role="button" aria-pressed="true">
<span class="fa fa-download mr-1" aria-hidden="true"></span>
<span>CSV Export</span>
Expand Down
14 changes: 14 additions & 0 deletions adserver/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,20 @@ def test_advertiser_geo_report_contents(self):
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)

def test_advertiser_perday_report_contents(self):
url = reverse("advertiser_per_ad_report", args=[self.advertiser1.slug])

# Anonymous
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertTrue(response["location"].startswith("/accounts/login/"))

self.client.force_login(self.staff_user)

# Metabase-only report
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)

def test_advertiser_publisher_report_contents(self):
get(
Offer,
Expand Down
6 changes: 6 additions & 0 deletions adserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .views import AdvertiserGeoReportView
from .views import AdvertiserKeywordReportView
from .views import AdvertiserMainView
from .views import AdvertiserPerAdPerDayReportView
from .views import AdvertiserPublisherReportView
from .views import AdvertiserReportView
from .views import AdvertiserStripePortalView
Expand Down Expand Up @@ -167,6 +168,11 @@
AdvertiserGeoReportView.as_view(export=True),
name="advertiser_geo_report_export",
),
path(
r"advertiser/<slug:advertiser_slug>/report/ad-breakdown/",
AdvertiserPerAdPerDayReportView.as_view(),
name="advertiser_per_ad_report",
),
path(
r"advertiser/<slug:advertiser_slug>/report/publishers/",
AdvertiserPublisherReportView.as_view(),
Expand Down
24 changes: 24 additions & 0 deletions adserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,30 @@ def get_context_data(self, **kwargs):
return context


class AdvertiserPerAdPerDayReportView(AdvertiserAccessMixin, BaseReportView):
"""A report for an advertiser broken down by day and by ad."""

impression_model = GeoImpression
template_name = "adserver/reports/advertiser-per-ad.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

advertiser_slug = kwargs.get("advertiser_slug", "")
advertiser = get_object_or_404(Advertiser, slug=advertiser_slug)

context.update(
{
"advertiser": advertiser,
"metabase_advertiser_per_ad": settings.METABASE_QUESTIONS.get(
"ADVERTISER_PER_AD_TABLE"
),
}
)

return context


class AdvertiserPublisherReportView(AdvertiserAccessMixin, BaseReportView):
"""A report for an advertiser broken down by publishers where the advertisers ads are shown."""

Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
"PUBLISHER_KEYWORD_REPORT": 318,
"PUBLISHER_GEO_REPORT": 319,
"ADVERTISER_TOPIC_PERFORMANCE": 366,
"ADVERTISER_PER_AD_TABLE": 966,
}
METABASE_DASHBOARDS = {
"ADVERTISER_FIGURES": 80,
Expand Down

0 comments on commit 15629d7

Please sign in to comment.