Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#71666 Sync latest changes to @types/google…
Browse files Browse the repository at this point in the history
…-publisher-tag by @publisher-ads-audits-bot

Co-authored-by: jimper <[email protected]>
  • Loading branch information
publisher-ads-audits-bot and jimper authored Jan 16, 2025
1 parent e6f454f commit db65e0a
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 122 deletions.
156 changes: 94 additions & 62 deletions types/google-publisher-tag/google-publisher-tag-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Tests for Google Publisher Tag 1.20241202
// Synced from: https://github.com/googleads/google-publisher-tag-types/commit/11a67de54de9180e5f3cf31c23c402f43071cdca
// Tests for Google Publisher Tag 1.20250113
// Synced from: https://github.com/googleads/google-publisher-tag-types/commit/86021d60da45fad4962a10ec47a079e9e0356ac7

// Test for googletag.cmd
function test_googletag_cmd() {
Expand Down Expand Up @@ -895,57 +895,77 @@ function test_googletag_events_slotResponseReceived() {

// Test for googletag.events.RewardedSlotGrantedEvent
function test_googletag_events_rewardedSlotGrantedEvent() {
// This listener is called whenever a reward is granted for a
// rewarded ad.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("rewardedSlotGranted", event => {
const slot = event.slot;
console.group("Reward granted for slot", slot.getSlotElementId(), ".");

// Log details of the reward.
console.log("Reward type:", event.payload?.type);
console.log("Reward amount:", event.payload?.amount);
console.groupEnd();

if (slot === targetSlot) {
// Slot specific logic.
}
});
const targetSlot = googletag.defineOutOfPageSlot("/1234567/example", googletag.enums.OutOfPageFormat.REWARDED);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
targetSlot.addService(googletag.pubads());

// This listener is called whenever a reward is granted for a
// rewarded ad.
googletag.pubads().addEventListener("rewardedSlotGranted", event => {
const slot = event.slot;
console.group("Reward granted for slot", slot.getSlotElementId(), ".");

// Log details of the reward.
console.log("Reward type:", event.payload?.type);
console.log("Reward amount:", event.payload?.amount);
console.groupEnd();

if (slot === targetSlot) {
// Slot specific logic.
}
});
}
}

// Test for googletag.events.RewardedSlotClosedEvent
function test_googletag_events_rewardedSlotClosedEvent() {
// This listener is called when the user closes a rewarded ad slot.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("rewardedSlotClosed", event => {
const slot = event.slot;
console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed.");
const targetSlot = googletag.defineOutOfPageSlot("/1234567/example", googletag.enums.OutOfPageFormat.REWARDED);

if (slot === targetSlot) {
// Slot specific logic.
}
});
// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
targetSlot.addService(googletag.pubads());

// This listener is called when the user closes a rewarded ad slot.
googletag.pubads().addEventListener("rewardedSlotClosed", event => {
const slot = event.slot;
console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed.");

if (slot === targetSlot) {
// Slot specific logic.
}
});
}
}

// Test for googletag.events.RewardedSlotReadyEvent
function test_googletag_events_rewardedSlotReadyEvent() {
// This listener is called when a rewarded ad slot becomes ready to be
// displayed.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("rewardedSlotReady", event => {
const slot = event.slot;
console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed.");

// Replace with custom logic.
const userHasConsented = true;
if (userHasConsented) {
event.makeRewardedVisible();
}

if (slot === targetSlot) {
// Slot specific logic.
}
});
const targetSlot = googletag.defineOutOfPageSlot("/1234567/example", googletag.enums.OutOfPageFormat.REWARDED);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
targetSlot.addService(googletag.pubads());

// This listener is called whenever a reward is granted for a
// rewarded ad.
googletag.pubads().addEventListener("rewardedSlotReady", event => {
const slot = event.slot;
console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed.");

// Replace with custom logic.
const userHasConsented = true;
if (userHasConsented) {
event.makeRewardedVisible();
}

if (slot === targetSlot) {
// Slot specific logic.
}
});
}
}

// Test for googletag.events.GameManualInterstitialSlotReadyEvent
Expand All @@ -956,35 +976,47 @@ function test_googletag_events_gameManualInterstitialSlotReadyEvent() {
"/1234567/example",
googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);
googletag.pubads().addEventListener("gameManualInterstitialSlotReady", event => {
const slot = event.slot;
console.log("Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.");

// Replace with custom logic.
const displayGmiAd = true;
if (displayGmiAd) {
event.makeGameManualInterstitialVisible();
}
// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
targetSlot.addService(googletag.pubads());

if (slot === targetSlot) {
// Slot specific logic.
}
});
googletag.pubads().addEventListener("gameManualInterstitialSlotReady", event => {
const slot = event.slot;
console.log("Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.");

// Replace with custom logic.
const displayGmiAd = true;
if (displayGmiAd) {
event.makeGameManualInterstitialVisible();
}

if (slot === targetSlot) {
// Slot specific logic.
}
});
}
}

// Test for googletag.events.GameManualInterstitialSlotClosedEvent
function test_googletag_events_gameManualInterstitialSlotClosedEvent() {
// This listener is called when a game manual interstial slot is closed.
// This listener is called when a game manual interstitial slot is closed.
const targetSlot = googletag.defineOutOfPageSlot(
"/1234567/example",
googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);
googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", event => {
const slot = event.slot;
console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed.");

if (slot === targetSlot) {
// Slot specific logic.
}
});
// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
targetSlot.addService(googletag.pubads());

googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", event => {
const slot = event.slot;
console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed.");

if (slot === targetSlot) {
// Slot specific logic.
}
});
}
}
Loading

0 comments on commit db65e0a

Please sign in to comment.