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

chore(pong): update mapping #9884

Merged
merged 4 commits into from
Nov 6, 2023
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
30 changes: 1 addition & 29 deletions client/src/placement-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useSWR from "swr";
import { PLACEMENT_ENABLED } from "./env";
import { useUserData } from "./user-context";
import { useLocation } from "react-router";
import { Payload as PlacementData } from "../../libs/pong/types";

export enum Status {
success = "success",
Expand All @@ -13,35 +14,6 @@ export enum Status {
empty = "empty",
}

export interface Fallback {
click: string;
view: string;
copy: string;
image: string;
by: string;
}

export interface PlacementData {
status: Status;
click?: string;
view?: string;
copy?: string;
image?: string;
fallback?: Fallback;
cta?: string;
colors?: {
textColor?: string;
backgroundColor?: string;
ctaTextColor?: string;
ctaBackgroundColor?: string;
textColorDark?: string;
backgroundColorDark?: string;
ctaTextColorDark?: string;
ctaBackgroundColorDark?: string;
};
version?: number;
}

type PlacementType = "side" | "top" | "hpMain" | "hpFooter" | "bottom";
export interface PlacementContextData
extends Partial<Record<PlacementType, PlacementData>> {
Expand Down
23 changes: 12 additions & 11 deletions client/src/ui/organisms/placement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import { User, useUserData } from "../../../user-context";

import "./index.scss";
import { useGleanClick } from "../../../telemetry/glean-context";
import {
PlacementData,
Status,
usePlacement,
} from "../../../placement-context";
import { Status, usePlacement } from "../../../placement-context";
import { Payload as PlacementData } from "../../../../../libs/pong/types";
import { BANNER_AI_HELP_CLICK } from "../../../telemetry/constants";

interface Timer {
Expand All @@ -24,6 +21,7 @@ interface PlacementRenderArgs {
extraClassNames?: string[];
click: string;
image: string;
alt?: string;
imageWidth: number;
imageHeight: number;
copy?: string;
Expand Down Expand Up @@ -276,8 +274,7 @@ export function PlacementInner({
};
}, [isVisible, isIntersecting, sendViewed]);

const { image, copy } = pong?.fallback || pong || {};
const { click, version } = pong || {};
const { image, copy, alt, click, version } = pong || {};
return (
<>
{!isServer &&
Expand All @@ -287,6 +284,7 @@ export function PlacementInner({
extraClassNames,
click,
image,
alt,
imageWidth,
imageHeight,
copy,
Expand All @@ -305,6 +303,7 @@ function RenderSideOrTopBanner({
extraClassNames = [],
click,
image,
alt,
imageWidth,
imageHeight,
copy,
Expand Down Expand Up @@ -332,8 +331,8 @@ function RenderSideOrTopBanner({
>
<img
src={`/pimg/${encodeURIComponent(image || "")}`}
aria-hidden="true"
alt=""
aria-hidden={!Boolean(alt)}
alt={alt || ""}
width={imageWidth}
height={imageHeight}
></img>
Expand Down Expand Up @@ -385,6 +384,7 @@ function RenderHpPlacement({
extraClassNames = [],
click,
image,
alt,
imageWidth,
imageHeight,
copy,
Expand All @@ -409,7 +409,7 @@ function RenderHpPlacement({
>
<img
src={`/pimg/${encodeURIComponent(image || "")}`}
alt={copy}
alt={alt || copy}
width={imageWidth}
height={imageHeight}
></img>
Expand All @@ -423,6 +423,7 @@ function RenderBottomBanner({
extraClassNames = [],
click,
image,
alt,
imageWidth,
imageHeight,
copy,
Expand All @@ -448,7 +449,7 @@ function RenderBottomBanner({
>
<img
src={`/pimg/${encodeURIComponent(image || "")}`}
alt={copy}
alt={alt || copy}
width={imageWidth}
height={imageHeight}
></img>
Expand Down
70 changes: 38 additions & 32 deletions libs/pong/pong2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,56 @@ export function createPong2GetHandler(zoneKeys, coder) {
});

const requests = placements.map(async ({ name, zoneKey }) => {
const {
ads: [
{
description = null,
statlink,
statimp,
smallImage,
backgroundColor,
backgroundHoverColor,
callToAction,
ctaBackgroundColor,
ctaBackgroundHoverColor,
ctaTextColor,
ctaTextColorHover,
textColor,
textColorHover,
},
] = [],
} = await (
const res = await (
await fetch(
`https://srv.buysellads.com/ads/${zoneKey}.json?forwardedip=${encodeURIComponent(
anonymousIp
)}${userAgent ? `&useragent=${encodeURIComponent(userAgent)}` : ""}`
)
).json();
const {
ads: [
{
statlink = null,
statimp,
Description,
Image,
ImageTitle,
BackgroundColor,
BackgroundColorLight,
BackgroundColorDark,
CallToAction,
CtaBackgroundColorLight,
CtaBackgroundColorDark,
CtaTextColorLight,
CtaTextColorDark,
TextColor,
TextColorLight,
TextColorDark,
},
] = [],
} = res;
return {
name,
p:
description === null
statlink === null
? null
: {
click: coder.encodeAndSign(statlink),
view: coder.encodeAndSign(statimp),
image: coder.encodeAndSign(smallImage),
copy: description && he.decode(description),
cta: callToAction && he.decode(callToAction),
image: coder.encodeAndSign(Image),
alt: ImageTitle && he.decode(ImageTitle),
copy: Description && he.decode(Description),
cta: CallToAction && he.decode(CallToAction),
colors: {
textColor,
backgroundColor,
ctaTextColor,
ctaBackgroundColor,
textColorDark: textColorHover,
backgroundColorDark: backgroundHoverColor,
ctaTextColorDark: ctaTextColorHover,
ctaBackgroundColorDark: ctaBackgroundHoverColor,
textColor: TextColor || TextColorLight,
backgroundColor: BackgroundColor || BackgroundColorLight,
ctaTextColor: CtaTextColorLight,
ctaBackgroundColor: CtaBackgroundColorLight,
textColorDark: TextColorDark,
backgroundColorDark: BackgroundColorDark,
ctaTextColorDark: CtaTextColorDark,
ctaBackgroundColorDark: CtaBackgroundColorDark,
},
},
};
Expand Down Expand Up @@ -86,13 +91,14 @@ export function createPong2GetHandler(zoneKeys, coder) {
if (v === null) {
return null;
}
const { copy, image, click, view, cta, colors = {} } = v;
const { copy, image, alt, click, view, cta, colors = {} } = v;
return [
p,
{
status: "success",
copy,
image,
alt,
cta,
colors,
click,
Expand Down
1 change: 1 addition & 0 deletions libs/pong/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type Payload = {
view: string;
copy?: string;
image?: string;
alt?: string;
cta?: string;
colors?: Colors;
version: number;
Expand Down