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

Add edition targeting to liveblog top sponsorship #27279

Merged
merged 5 commits into from
Jul 9, 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
1 change: 1 addition & 0 deletions admin/app/dfp/DfpDataExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ case class DfpDataExtractor(lineItems: Seq[GuLineItem], invalidLineItems: Seq[Gu
lineItemName = lineItem.name,
lineItemId = lineItem.id,
adTest = lineItem.targeting.adTestValue,
editions = editionsTargeted(lineItem),
sections = lineItem.liveBlogTopTargetedSections,
targetsAdTest = lineItem.targeting.hasAdTestTargetting,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>LiveBlog Top Sponsorships</h1>
<li>Targets the <pre>culture</pre>,<pre>sport</pre> or <pre>football</pre> section</li>
<li>Targets the <pre>liveblog</pre> content type</li>
<li>Targets the <pre>mobile</pre> breakpoint</li>
<li>Targets an edition</li>
</ol>

<h2>Sponsorships</h2>
Expand All @@ -42,6 +43,7 @@ <h2>Sponsorships</h2>
<pre>@section</pre>@if(section != sponsorship.sections.last) {, }
}
@if(sponsorship.targetsAdTest) {<br /><small>Adtest:</small> <pre>@sponsorship.adTest</pre>}
@if(!sponsorship.editions.isEmpty) {<br /><small>Editions:</small> @for(edition <- sponsorship.editions.map(_.id)) {<pre>@edition</pre>@if(edition != sponsorship.editions.last.id) {, }}}
</li>
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/app/common/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class GuardianConfiguration extends GuLogging {
lazy val dfpInlineMerchandisingTagsDataKey = s"$dfpRoot/inline-merchandising-tags-v3.json"
lazy val dfpHighMerchandisingTagsDataKey = s"$dfpRoot/high-merchandising-tags.json"
lazy val dfpPageSkinnedAdUnitsKey = s"$dfpRoot/pageskinned-adunits-v9.json"
lazy val dfpLiveBlogTopSponsorshipDataKey = s"$dfpRoot/liveblog-top-sponsorships.json"
lazy val dfpLiveBlogTopSponsorshipDataKey = s"$dfpRoot/liveblog-top-sponsorships-v2.json"
lazy val dfpNonRefreshableLineItemIdsKey = s"$dfpRoot/non-refreshable-lineitem-ids-v1.json"
lazy val dfpLineItemsKey = s"$dfpRoot/lineitems-v7.json"
lazy val dfpActiveAdUnitListKey = s"$dfpRoot/active-ad-units.csv"
Expand Down
4 changes: 3 additions & 1 deletion common/app/common/dfp/DfpData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ case class GuLineItem(

val isSponsorship = lineItemType == Sponsorship

isLiveblogTopSlot && isLiveblogContentType && targetsOnlyAllowedSections && isMobileBreakpoint && isSponsorship
val hasEditionTargeting = targeting.editions.nonEmpty

isLiveblogTopSlot && isLiveblogContentType && targetsOnlyAllowedSections && isMobileBreakpoint && isSponsorship && hasEditionTargeting
Comment on lines +311 to +313
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it right to assume its looking at the targeting data received from GAM at this point?

}

lazy val targetsNetworkOrSectionFrontDirectly: Boolean = {
Expand Down
22 changes: 15 additions & 7 deletions common/app/common/dfp/LiveBlogTopSponsorshipAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common.dfp
import model.Tag
import model.ContentType
import model.Section
import common.Edition
import play.api.mvc.RequestHeader
import model.{MetaData}
import model.DotcomContentType
Expand All @@ -12,20 +13,27 @@ trait LiveBlogTopSponsorshipAgent {

protected def liveBlogTopSponsorships: Seq[LiveBlogTopSponsorship]

private[dfp] def findSponsorships(
edition: Edition,
sectionId: String,
adTest: Option[String],
): Seq[LiveBlogTopSponsorship] = {
liveBlogTopSponsorships.filter { sponsorship =>
sponsorship.editions.contains(edition) && sponsorship.sections.contains(sectionId) && sponsorship
.matchesTargetedAdTest(adTest)
}
}

def hasLiveBlogTopAd(metadata: MetaData, request: RequestHeader): Boolean = {
if (
metadata.contentType == Some(DotcomContentType.LiveBlog) && ActiveExperiments.isParticipating(
LiveBlogTopSponsorship,
)(request)
) {
val adTest = request.getQueryString("adtest")
liveBlogTopSponsorships.exists { sponsorship =>
if (sponsorship.targetsAdTest) {
sponsorship.hasTargetedSection(metadata.sectionId) && sponsorship.adTest == adTest
} else {
sponsorship.hasTargetedSection(metadata.sectionId)
}
}
val edition = Edition(request)

findSponsorships(edition, metadata.sectionId, adTest).nonEmpty
} else {
false
}
Expand Down
9 changes: 4 additions & 5 deletions common/app/common/dfp/LiveblogTopSponsorship.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ case class LiveBlogTopSponsorship(
lineItemName: String,
lineItemId: Long,
sections: Seq[String],
editions: Seq[Edition],
adTest: Option[String],
targetsAdTest: Boolean,
) {
def hasTargetedSection(section: String): Boolean = section.isEmpty || this.sections.contains(section)

def hasTargetedAdTest(adTest: String): Boolean = this.adTest == Some(adTest)

def nonEmpty: Boolean = sections.nonEmpty
def matchesTargetedAdTest(adTest: Option[String]): Boolean =
if (this.targetsAdTest) { adTest == this.adTest }
else { true }
}

object LiveBlogTopSponsorship {
Expand Down