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

Per ad per day advertiser table/export #921

Merged
merged 2 commits into from
Oct 10, 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
40 changes: 40 additions & 0 deletions adserver/templates/adserver/reports/advertiser-per-ad.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% 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>
<span>{% trans 'This report shows a table of data with one entry for each ad for every day that ad is shown.' %} </span>
<span><strong>{% trans 'The data can be exported to CSV/Excel for further analysis with the icon at the bottom right.' %}</strong></span>
</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">
Copy link
Member

Choose a reason for hiding this comment

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

I wonder about putting it in the sidebar under Reports as well? Maybe after we test it a bit more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good.

<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
Loading