Skip to content

Commit

Permalink
Project import generated by Copybara
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 731928957
  • Loading branch information
jimper authored and copybara-github committed Feb 28, 2025
1 parent 95474ce commit 2299534
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data/localization/en.xlb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<msg name="sc5c8140d066b7231" desc="Code comment preceding a call to googletag.enableServices().">// Enable GPT services.</msg>
<msg name="s5ec0955e7a33abf4" desc="Code comment preceding a call to googletag.enableSingleRequest().">// Enable single request mode.</msg>
<msg name="s71e012bd812c44a2" desc="Code comment preceding ad slot definitions.">// Define static ad slots.</msg>
<msg name="s2fe608b6b49c885b" desc="Code comment preceding calls to configure AdSense settings.">// Set AdSense attributes.</msg>
<msg name="s5e13187e6961d8b1" desc="Code comment preceding out-of-page ad slot definitions.">// Define out-of-page slots.</msg>
<msg name="s34774a88f199f364" desc="Code comment preceding page-level targeting configuration.">// Configure page-level targeting.</msg>
<msg name="s0536dee760be4bf2" desc="Code comment preceding privacy settings configuration.">// Configure privacy settings.</msg>
Expand Down Expand Up @@ -51,6 +52,7 @@
<msg name="sf93d227444bc5687" desc="Section containing page settings.">Page settings</msg>
<msg name="s758d8c59379ea482" desc="Section containing page-level targeting options.">Page-level targeting</msg>
<msg name="se78c02e9a98a0f47" desc="Section containing privacy settings.">Privacy</msg>
<msg name="sdee10f7d35f52edf" desc="Settings that affect AdSense behavior.">AdSense attributes</msg>
<msg name="s352f8b213acc822a" desc="Status message: An ad slot of the specified format has loaded."><ph name="0">${format}</ph> is loaded.</msg>
<msg name="s9d21580cc7643953" desc="Status message: An out-of-page ad is loading."><ph name="0">${format}</ph> is loading...</msg>
<msg name="s8233e942045a2b50" desc="Status message: The specified out-of-page format is not supported on the current page."><ph name="0">${format}</ph> is not supported on this page.</msg>
Expand All @@ -60,6 +62,7 @@
<msg name="sa2b2ab2dd02accfd" desc="The action of clicking on a link.">Link click</msg>
<msg name="s1c1f567a55f86cc2" desc="The action of hiding and then returning to the page (for example, by switching tabs).">Unhide window</msg>
<msg name="seb61938dbbd0dd2b" desc="The action of interacting with the browser navigation bar.">Browser navigation</msg>
<msg name="s1c67a1fa4d07bd8b" desc="The page URL to associate with ad requests.">Page URL</msg>
<msg name="s9dc1289fa45bd694" desc="User actions that can trigger an intersitial ad.">Interstitial triggers</msg>
<msg name="s2a071e5a3e79454a" desc="Valid format for user key-value input">Key=Value1,Value2,...</msg>
<msg name="s8e732383cac5c9fd" desc="Valid formats for user size input">100x100,fluid,...</msg>
Expand Down
3 changes: 3 additions & 0 deletions data/localization/test.xlb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<msg name="sc5c8140d066b7231" desc="Code comment preceding a call to googletag.enableServices().">// Ến̂ấb̂l̂́ê Ĝ́P̂T̂́ ŝ́êr̂́v̂î́ĉếŝ.</msg>
<msg name="s5ec0955e7a33abf4" desc="Code comment preceding a call to googletag.enableSingleRequest().">// Ến̂ấb̂l̂́ê ŝ́în̂́ĝl̂́ê r̂́êq̂́ûếŝt̂́ m̂́ôd̂́ê.</msg>
<msg name="s71e012bd812c44a2" desc="Code comment preceding ad slot definitions.">// D̂́êf̂́în̂́ê ŝ́t̂ất̂î́ĉ ấd̂ ŝ́l̂ốt̂ŝ́.</msg>
<msg name="s2fe608b6b49c885b" desc="Code comment preceding calls to configure AdSense settings.">// Ŝ́êt̂́ Ấd̂Ŝ́ên̂́ŝế ất̂t̂́r̂î́b̂û́t̂ếŝ.</msg>
<msg name="s5e13187e6961d8b1" desc="Code comment preceding out-of-page ad slot definitions.">// D̂́êf̂́în̂́ê ốût̂́-ốf̂-p̂́âĝ́ê ŝ́l̂ốt̂ŝ́.</msg>
<msg name="s34774a88f199f364" desc="Code comment preceding page-level targeting configuration.">// Ĉ́ôn̂́f̂î́ĝû́r̂ế p̂́âĝ́ê-l̂́êv̂́êl̂́ t̂́âr̂́ĝết̂î́n̂ĝ́.</msg>
<msg name="s0536dee760be4bf2" desc="Code comment preceding privacy settings configuration.">// Ĉ́ôn̂́f̂î́ĝû́r̂ế p̂́r̂î́v̂ấĉŷ́ ŝ́êt̂́t̂î́n̂ĝ́ŝ.</msg>
Expand Down Expand Up @@ -51,6 +52,7 @@
<msg name="sf93d227444bc5687" desc="Section containing page settings.">P̂́âĝ́ê ŝ́êt̂́t̂î́n̂ĝ́ŝ</msg>
<msg name="s758d8c59379ea482" desc="Section containing page-level targeting options.">P̂́âĝ́ê-l̂́êv̂́êl̂́ t̂́âr̂́ĝết̂î́n̂ĝ́</msg>
<msg name="se78c02e9a98a0f47" desc="Section containing privacy settings.">P̂́r̂î́v̂ấĉŷ́</msg>
<msg name="sdee10f7d35f52edf" desc="Settings that affect AdSense behavior.">Ấd̂Ŝ́ên̂́ŝế ất̂t̂́r̂î́b̂û́t̂ếŝ</msg>
<msg name="s352f8b213acc822a" desc="Status message: An ad slot of the specified format has loaded."><ph name="0">${format}</ph> î́ŝ l̂́ôấd̂ếd̂.</msg>
<msg name="s9d21580cc7643953" desc="Status message: An out-of-page ad is loading."><ph name="0">${format}</ph> î́ŝ l̂́ôấd̂î́n̂ĝ́...</msg>
<msg name="s8233e942045a2b50" desc="Status message: The specified out-of-page format is not supported on the current page."><ph name="0">${format}</ph> î́ŝ n̂́ôt̂́ ŝ́ûp̂́p̂ốr̂t̂́êd̂́ ốn̂ t̂́ĥî́ŝ p̂́âĝ́ê.</msg>
Expand All @@ -60,6 +62,7 @@
<msg name="sa2b2ab2dd02accfd" desc="The action of clicking on a link.">L̂́în̂́k̂ ĉ́l̂î́ĉk̂́</msg>
<msg name="s1c1f567a55f86cc2" desc="The action of hiding and then returning to the page (for example, by switching tabs).">Û́n̂ĥ́îd̂́ê ŵ́în̂́d̂ốŵ</msg>
<msg name="seb61938dbbd0dd2b" desc="The action of interacting with the browser navigation bar.">B̂́r̂ốŵŝ́êr̂́ n̂́âv̂́îĝ́ât̂́îốn̂</msg>
<msg name="s1c67a1fa4d07bd8b" desc="The page URL to associate with ad requests.">P̂́âĝ́ê Û́R̂L̂́</msg>
<msg name="s9dc1289fa45bd694" desc="User actions that can trigger an intersitial ad.">Î́n̂t̂́êr̂́ŝt̂́ît̂́îấl̂ t̂́r̂î́ĝĝ́êr̂́ŝ</msg>
<msg name="s2a071e5a3e79454a" desc="Valid format for user key-value input">K̂́êŷ́=V̂́âl̂́ûế1,V̂́âl̂́ûế2,...</msg>
<msg name="s8e732383cac5c9fd" desc="Valid formats for user size input">100x̂́100,f̂́l̂û́îd̂́,...</msg>
Expand Down
21 changes: 21 additions & 0 deletions src/codegen/api/pubads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {
SampleAdSenseAttributeConfig,
SamplePrivacyConfig,
SampleTargetingKV,
} from '../../model/sample-config.js';
Expand Down Expand Up @@ -42,6 +43,11 @@ const api = {
`childDirectedTreatment: ${sanitizeJs(enabled)}`,
tfua: (enabled: boolean) => `underAgeOfConsent: ${sanitizeJs(enabled)}`,
},

set: {
pageUrl: (url: string) =>
`${api.pubAdsService()}.set('page_url', ${sanitizeJs(url)})`,
},
};

/* Public exports */
Expand All @@ -64,6 +70,21 @@ export function enableSingleRequest() {
return api.enableSingleRequest() + ';';
}

/**
* Generates code for setting AdSense attributes.
*/
export function setAdSenseAttributes(
adSenseConfig: SampleAdSenseAttributeConfig,
) {
const adSenseAttributes: string[] = [];

if (adSenseConfig.pageUrl) {
adSenseAttributes.push(api.set.pageUrl(adSenseConfig.pageUrl) + ';');
}

return adSenseAttributes.length > 0 ? adSenseAttributes.join('\n') : '';
}

/**
* Generates code for configuring page-level privacy settings.
*
Expand Down
10 changes: 10 additions & 0 deletions src/codegen/gpt-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import * as pubads from './api/pubads.js';
/* Internal template strings */

const strings = {
setAdSenseAttributesComment: () =>
msg('// Set AdSense attributes.', {
desc: 'Code comment preceding calls to configure AdSense settings.',
}),
staticSlotComment: () =>
msg('// Define static ad slots.', {
desc: 'Code comment preceding ad slot definitions.',
Expand Down Expand Up @@ -91,6 +95,9 @@ function initGpt(config: SampleConfig, requestAndRenderAds: boolean) {
const staticSlots = slotDefinitions(config);
const outOfPageSlots = slotDefinitions(config, true);

const adSenseAttributes = pubads.setAdSenseAttributes(
config.page?.adsense || {},
);
const pageTargeting = pubads.setTargeting(config.page?.targeting || []);
const privacySettings = pubads.setPrivacySettings(config.page?.privacy || {});

Expand All @@ -107,6 +114,9 @@ function initGpt(config: SampleConfig, requestAndRenderAds: boolean) {
${pageTargeting.length > 0 ? strings.pageTargetingComment() : ''}
${pageTargeting}
${adSenseAttributes.length > 0 ? strings.setAdSenseAttributesComment() : ''}
${adSenseAttributes}
${config.page?.sra ? strings.enableSraComment() : ''}
${config.page?.sra ? pubads.enableSingleRequest() : ''}
Expand Down
3 changes: 3 additions & 0 deletions src/generated/locales/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export const templates = {
s1163c710c6c9bccf: 'Ĝ́âm̂́în̂́ĝ î́n̂t̂́êr̂́ŝt̂́ît̂́îấl̂ ấd̂',
s11a3c998dc1af0b1: 'Ŝ́âm̂́p̂l̂́ê ấd̂ŝ́',
s1c1f567a55f86cc2: 'Û́n̂ĥ́îd̂́ê ŵ́în̂́d̂ốŵ',
s1c67a1fa4d07bd8b: 'P̂́âĝ́ê Û́R̂L̂́',
s267a52c34c200ef0: 'Ŝ́în̂́ĝl̂́ê R̂́êq̂́ûếŝt̂́ Ấr̂ĉ́ĥî́t̂ếĉt̂́ûr̂́ê (Ŝ́R̂Ấ)',
s292d08a9cea72454: 'F̂́l̂û́îd̂́ ấd̂',
s2a071e5a3e79454a: 'K̂́êŷ́=V̂́âl̂́ûế1,V̂́âl̂́ûế2,...',
s2d647200b120ea41: 'Ấd̂ û́n̂î́t̂ p̂́ât̂́ĥ',
s2fe608b6b49c885b: '// Ŝ́êt̂́ Ấd̂Ŝ́ên̂́ŝế ất̂t̂́r̂î́b̂û́t̂ếŝ.',
s3132d1a0580760bc: 'Ĉ́ĥî́l̂d̂́-d̂́îr̂́êĉ́t̂ếd̂ t̂́r̂ếât̂́m̂ến̂t̂́',
s3400fb34f1e245a9: 'M̂́ûl̂́t̂î́-ŝ́îẑ́ê ấd̂',
s34774a88f199f364: '// Ĉ́ôn̂́f̂î́ĝû́r̂ế p̂́âĝ́ê-l̂́êv̂́êl̂́ t̂́âr̂́ĝết̂î́n̂ĝ́.',
Expand Down Expand Up @@ -84,6 +86,7 @@ export const templates = {
sd3926a53f7b06107: '// R̂́êq̂́ûếŝt̂́ ấn̂d̂́ r̂́ên̂́d̂ếr̂ ấl̂l̂́ p̂́r̂ếv̂î́ôû́ŝl̂́ŷ d̂́êf̂́în̂́êd̂́ ấd̂ ŝ́l̂ốt̂ŝ́.',
sd4801ff24e6e00e1: str`N̂́ô v̂́âl̂́ûế f̂́ôr̂́ k̂́êŷ́: ${0}`,
sd5ac53cfd233dbcb: 'L̂́îm̂́ît̂́êd̂́ ấd̂ŝ́',
sdee10f7d35f52edf: 'Ấd̂Ŝ́ên̂́ŝế ất̂t̂́r̂î́b̂û́t̂ếŝ',
se6dd79643508bb80: 'T̂́âr̂́ĝết̂î́n̂ĝ́',
se78c02e9a98a0f47: 'P̂́r̂î́v̂ấĉŷ́',
seb61938dbbd0dd2b: 'B̂́r̂ốŵŝ́êr̂́ n̂́âv̂́îĝ́ât̂́îốn̂',
Expand Down
8 changes: 8 additions & 0 deletions src/model/sample-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ export interface SampleConfig {
* Page-level GPT settings.
*/
export interface SamplePageConfig {
adsense?: SampleAdSenseAttributeConfig;
privacy?: SamplePrivacyConfig;
sra?: boolean;
targeting?: SampleTargetingKV[];
}

/**
* AdSense attributes.
*/
export interface SampleAdSenseAttributeConfig {
pageUrl?: string;
}

/**
* Privacy-related GPT settings.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/model/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {msg} from '@lit/localize';

import {
SampleAdSenseAttributeConfig,
SampleConfig,
SamplePageConfig,
SamplePrivacyConfig,
Expand All @@ -40,6 +41,10 @@ export const configNames: Record<keyof SampleConfig, () => string> = {
* Maps {@link SamplePageConfig} properties to their friendly names.
*/
export const pageConfigNames: Record<keyof SamplePageConfig, () => string> = {
adsense: () =>
msg('AdSense attributes', {
desc: 'Settings that affect AdSense behavior.',
}),
privacy: () => msg('Privacy', {desc: 'Section containing privacy settings.'}),
sra: () =>
msg('Single Request Architecture (SRA)', {
Expand All @@ -51,6 +56,19 @@ export const pageConfigNames: Record<keyof SamplePageConfig, () => string> = {
}),
};

/**
* Maps {@link SampleAdSenseAttributeConfig} properties to their friendly names.
*/
export const adSenseAttributeConfigNames: Record<
keyof SampleAdSenseAttributeConfig,
() => string
> = {
pageUrl: () =>
msg('Page URL', {
desc: 'The page URL to associate with ad requests.',
}),
};

/**
* Maps {@link SamplePrivacyConfig} properties to their friendly names.
*/
Expand Down

0 comments on commit 2299534

Please sign in to comment.