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

feat(pong): bottom banner #9883

Merged
merged 9 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion client/src/document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ export function Document(props /* TODO: define a TS interface for this */) {
<DocumentSurvey doc={doc} />
<RenderDocumentBody doc={doc} />
<Metadata doc={doc} locale={locale} />
<BottomBanner />
</article>
</MainContentContainer>
</div>
<BottomBanner />
</>
);
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/placement-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface PlacementData {
version?: number;
}

type PlacementType = "side" | "top" | "hpMain" | "hpFooter";
type PlacementType = "side" | "top" | "hpMain" | "hpFooter" | "bottom";
export interface PlacementContextData
extends Partial<Record<PlacementType, PlacementData>> {
status: Status;
Expand All @@ -53,6 +53,7 @@ const PLACEMENT_MAP: Record<PlacementType, RegExp> = {
top: /\/[^/]+\/(?!$|_homepage$).*/i,
hpMain: /\/[^/]+\/($|_homepage$)/i,
hpFooter: /\/[^/]+\/($|_homepage$)/i,
bottom: /\/[^/]+\/docs\//i,
};

function placementTypes(pathname: string): string[] {
Expand Down
67 changes: 67 additions & 0 deletions client/src/ui/organisms/placement/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,70 @@ div.empty-place {
--place-top-cta-background: var(--place-top-cta-background-dark);
--place-top-cta-color: var(--place-top-cta-color-dark);
}

.bottom-banner-container {
background-color: var(
--place-bottom-banner-background,
var(--background-primary)
);
color: var(--place-bottom-banner-color, var(--text-primary));
margin: 0;
width: 100%;

> section.place.bottom-banner {
column-gap: 3rem;
display: grid;
grid-template-areas:
"nope pong note"
"nope pong no";
grid-template-columns: minmax(0, 1fr) minmax(0, 2.5fr) minmax(0, 15rem);
margin: 0 auto;
max-width: var(--max-width);
padding: 0 1rem;

.pong {
grid-area: pong;
justify-self: center;

img {
height: auto;
}
}

.pong-note {
color: var(--place-bottom-banner-color, var(--text-primary));
font-size: 0.625rem;
grid-area: note;
margin-top: 0.5rem;
text-decoration: underline;
}

.no-pong {
color: var(--place-bottom-banner-color, var(--text-primary));
font-size: 0.625rem;
grid-area: no;
margin-top: auto;
}

@media screen and (max-width: $screen-xl) {
grid-template-areas:
"pong note"
"pong no";
grid-template-columns: auto max-content;
grid-template-rows: auto 2rem;
}

@media screen and (max-width: $screen-lg) {
grid-template-areas:
"pong pong"
"note no";
grid-template-columns: 1fr 1fr;
grid-template-rows: auto 2rem;

.no-pong {
justify-self: end;
width: fit-content;
}
}
}
}
106 changes: 94 additions & 12 deletions client/src/ui/organisms/placement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface PlacementRenderArgs {
user: User;
style: object;
version?: number;
typ: string;
}

const INTERSECTION_OPTIONS = {
Expand Down Expand Up @@ -148,6 +149,7 @@ export function HpMainPlacement() {
placementData: placementData?.hpMain,
imageWidth: 970,
imageHeight: 250,
typ: "hp-main",
});
}

Expand All @@ -157,17 +159,20 @@ export function HpFooterPlacement() {
placementData: placementData?.hpFooter,
imageWidth: 728,
imageHeight: 90,
typ: "hp-footer",
});
}

function HpPlacement({
placementData,
imageWidth,
imageHeight,
typ,
}: {
placementData?: PlacementData;
imageWidth: number;
imageHeight: number;
typ: string;
}) {
const { backgroundColor } = placementData?.colors || {};
const css = Object.fromEntries(
Expand All @@ -185,19 +190,30 @@ function HpPlacement({
imageHeight={imageHeight}
style={css}
renderer={RenderHpPlacement}
typ="hp-main"
typ={typ}
></PlacementInner>
);
}

export function BottomBanner() {
return (
const placementData = usePlacement()?.bottom;
const { backgroundColor, textColor } = placementData?.colors || {};
const css = Object.fromEntries(
[
["--place-bottom-banner-background", backgroundColor],
["--place-bottom-banner-color", textColor],
].filter(([_, v]) => Boolean(v))
);
return placementData ? (
<PlacementInner
pong={{ status: Status.empty }}
pong={placementData}
imageWidth={728}
imageHeight={90}
Comment on lines +210 to +211
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should these constants live somewhere else?

style={css}
renderer={RenderBottomBanner}
typ="bottom-banner"
/>
);
></PlacementInner>
) : null;
}

export function PlacementInner({
Expand Down Expand Up @@ -278,6 +294,7 @@ export function PlacementInner({
user,
style,
version,
typ,
})}
</>
);
Expand All @@ -295,6 +312,7 @@ function RenderSideOrTopBanner({
user,
style,
version = 1,
typ,
}: PlacementRenderArgs) {
return (
<section
Expand All @@ -305,7 +323,7 @@ function RenderSideOrTopBanner({
<p className="pong-box">
<a
className="pong"
data-glean="pong: pong->click"
data-glean={`pong: pong->click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
Expand All @@ -324,8 +342,10 @@ function RenderSideOrTopBanner({
{cta && (
<a
className="pong-cta"
data-glean="pong: pong->click"
href={`/pong/click?code=${encodeURIComponent(click)}`}
data-glean={`pong: pong->click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
target="_blank"
rel="noreferrer"
>
Expand Down Expand Up @@ -369,6 +389,8 @@ function RenderHpPlacement({
imageHeight,
copy,
style,
version = 1,
typ,
}: PlacementRenderArgs) {
return (
<section
Expand All @@ -378,8 +400,10 @@ function RenderHpPlacement({
>
<a
className="pong"
data-glean="pong: pong->click"
href={`/pong/click?code=${encodeURIComponent(click)}`}
data-glean={`pong: pong->click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
target="_blank"
rel="noreferrer"
>
Expand All @@ -394,6 +418,64 @@ function RenderHpPlacement({
);
}

function RenderBottomBanner({ place }: PlacementRenderArgs) {
return <div ref={place} className="empty-place bottom-banner"></div>;
function RenderBottomBanner({
place,
extraClassNames = [],
click,
image,
imageWidth,
imageHeight,
copy,
user,
style,
version = 1,
typ,
}: PlacementRenderArgs) {
return (
<div className="bottom-banner-container" style={style}>
<section
ref={place}
className={["place", "bottom-banner", ...extraClassNames].join(" ")}
>
<a
className="pong"
data-glean={`pong: pong->click ${typ}`}
href={`/pong/click?code=${encodeURIComponent(
click
)}&version=${version}`}
target="_blank"
rel="noreferrer"
>
<img
src={`/pimg/${encodeURIComponent(image || "")}`}
alt={copy}
width={imageWidth}
height={imageHeight}
></img>
</a>
<a
href="/en-US/advertising"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why en-US, not ${locale}? The page is available in other locales: https://developer.allizom.org/fr/advertising

className="pong-note"
data-glean="pong: pong->about"
target="_blank"
rel="noreferrer"
>
Mozilla ads
</a>
<a
className="no-pong"
data-glean={
"pong: " + (user?.isSubscriber ? "pong->settings" : "pong->plus")
}
href={
user?.isSubscriber
? "/en-US/plus/settings?ref=nope"
: "/en-US/plus?ref=nope#subscribe"
}
>
Don't want to see ads?
</a>
Comment on lines +440 to +477
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we could DRY up all this across all the renderers? But ok for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree.

</section>
</div>
);
}
8 changes: 7 additions & 1 deletion libs/pong/pong.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const PLACEMENTS = {
top: 585,
hpMain: 3214,
hpFooter: 2327,
bottom: 7748,
};

// Allow list for client sent keywords.
Expand Down Expand Up @@ -45,7 +46,12 @@ export function createPongGetHandler(client, coder) {
if (v === null || v?.[0] === null) {
return [p, null];
}
if ((p === "side") | (p === "hpMain") | (p === "hpFooter")) {
if (
(p === "side") |
(p === "hpMain") |
(p === "hpFooter") |
(p === "bottom")
fiji-flo marked this conversation as resolved.
Show resolved Hide resolved
) {
const [{ contents, clickUrl, impressionUrl }] = v;
const { colors } = contents?.[0]?.data?.customData || {};
return [
Expand Down
Loading