Skip to content

Commit 24f6ace

Browse files
gabelewpotench
authored andcommitted
Adds support for googletag.events.SlotOnloadEvent (#20) (#73)
1 parent bd753ee commit 24f6ace

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

docs/api/ReactGPT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ A React component which renders [GPT](https://support.google.com/dfp_sb/answer/1
2525
- `onSlotRenderEnded`(optional) - An optional event handler function for `googletag.events.SlotRenderEndedEvent`.
2626
- `onImpressionViewable`(optional) - An optional event handler function for `googletag.events.ImpressionViewableEvent`.
2727
- `onSlotVisibilityChanged`(optional) - An optional event handler function for `googletag.events.slotVisibilityChangedEvent`.
28+
- `onSlotLoad`(optional) - An optional event handler function for `googletag.events.SlotOnloadEvent`.
2829
- `renderWhenViewable`(optional) - An optional flag to indicate whether an ad should only render when it's fully in the viewport area.
2930
- `viewableThreshold`(optional) - An optional number to indicate how much percentage of an ad area needs to be in a viewable area before rendering. Acceptable range is between `0` and `1`.
3031
- `onScriptLoaded`(optional) - An optional call back function to notify when the script is loaded.

examples/apps/log.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ GPT.on(Events.SLOT_VISIBILITY_CHANGED, event => {
4242
const divId = slot.getSlotElementId();
4343
const sizes = slot.getSizes();
4444
console.log(`SLOT_VISIBILITY_CHANGED for ${divId}(${JSON.stringify(sizes)}) to ${event.inViewPercentage}`, event);
45+
});
46+
47+
GPT.on(Events.SLOT_LOADED, event => {
48+
const slot = event.slot;
49+
const divId = slot.getSlotElementId();
50+
const sizes = slot.getSizes();
51+
console.log(`SLOT_LOADED for ${divId}(${JSON.stringify(sizes)})`, event);
4552
});*/

src/Bling.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {createManager, pubadsAPI} from "./createManager";
1919
* @fires Bling#Events.SLOT_RENDER_ENDED
2020
* @fires Bling#Events.IMPRESSION_VIEWABLE
2121
* @fires Bling#Events.SLOT_VISIBILITY_CHANGED
22+
* @fires Bling#Events.SLOT_LOADED
2223
*/
2324
class Bling extends Component {
2425
static propTypes = {
@@ -154,6 +155,12 @@ class Bling extends Component {
154155
* @property onSlotVisibilityChanged
155156
*/
156157
onSlotVisibilityChanged: PropTypes.func,
158+
/**
159+
* An optional event handler function for `googletag.events.SlotOnloadEvent`.
160+
*
161+
* @property onSlotLoad
162+
*/
163+
onSlotLoad: PropTypes.func,
157164
/**
158165
* An optional flag to indicate whether an ad should only render when it's fully in the viewport area.
159166
*

src/Events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const Events = {
33
RENDER: "render",
44
SLOT_RENDER_ENDED: "slotRenderEnded",
55
IMPRESSION_VIEWABLE: "impressionViewable",
6-
SLOT_VISIBILITY_CHANGED: "slotVisibilityChanged"
6+
SLOT_VISIBILITY_CHANGED: "slotVisibilityChanged",
7+
SLOT_LOADED: "slotOnload"
78
};
89

910
export default Events;

src/createManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export class AdManager extends EventEmitter {
186186
[
187187
Events.SLOT_RENDER_ENDED,
188188
Events.IMPRESSION_VIEWABLE,
189-
Events.SLOT_VISIBILITY_CHANGED
189+
Events.SLOT_VISIBILITY_CHANGED,
190+
Events.SLOT_LOADED
190191
].forEach(eventType => {
191192
["pubads", "content", "companionAds"].forEach(service => {
192193
// there is no API to remove listeners.

0 commit comments

Comments
 (0)