Skip to content

Commit 7a36fc3

Browse files
authored
[MM] Feature: Add configurable collapsible ads (#122)
1 parent 18434df commit 7a36fc3

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ The dom element you’d like to place the ad into. You can pass either a DOMElem
7070
| offset | 0 | The offset of the viewport to consider the ad in view. This will not affect your provider’s internal viewability metrics, however it is used by the autoRefresh and autoRender options |
7171
| refreshRateInSeconds | 60 | If autoRefresh has been set to true, this value will be used to determine how long after an ad is in viewport (browsers scroll position + offset) until the ad should be refreshed for another impression. |
7272
| targeting | {} | Key value targeting values to be passed to your ad provider |
73-
| breakpoints | {} | Key value list of breakpoints. (e.g. { mobile: { from: 0, to: 480 }, desktop: { from: 481, to: Infinity } }) |
73+
| breakpoints | {} | Key value list of breakpoints. (e.g. { mobile: { from: 0, to: 480 }, desktop: { from: 481, to: Infinity } })
74+
| collapsible | false | Setting to true will cause ad to be collapsed by default and only expand if ad is filled. Warning! This feature can cause content shift and should be used with caution. [Collapsible Docs](https://developers.google.com/doubleclick-gpt/samples/collapse-empty-ad-slots) |
7475
| sizes | [] | Either an array of ad sizes (e.g. [[300, 600], [300, 250]]) or if you have specified breakpoints, a key value mapping to the breakpoints (e.g. { mobile: [[300, 250]], desktop: [[300, 600], [300, 250]] }). _Note: AdJS supports standard ad creative sizes out-of-the-box and recently introduced experimental support for fluid ads. If your ad provider is able to supply and target a fluid creative, all you should need is to add `['fluid']` to your array of ad sizes on all breakpoints you'd like to implement fluid ads via AdJS._ |
7576
| refreshOnBreakpoint | true | Should the ad automatically refresh when passing the values provided in breakpoints |
7677
| *provider options* | | Sometimes (though discouraged) an ad network will have additional options that are required or optional. See your network to see these additional options. |

docs/dfp-network.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,27 @@ const ad = new page.Ad(el, {
110110
}
111111
});
112112
```
113+
114+
115+
__Using Collapsible Ads__
116+
```js
117+
const AdJS = require('adjs');
118+
const DFPNetwork = require('adjs/networks/dfp');
119+
120+
const page = new AdJS.Page(DFPNetwork);
121+
122+
const ad = new page.Ad(el, {
123+
path: '/example/adunit/path',
124+
125+
targeting: {
126+
age: 30,
127+
gender: 'female'
128+
},
129+
130+
sizes: [
131+
[300, 250],
132+
],
133+
134+
collapsible: true,
135+
});
136+
```

docs/error.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ Example:
3939
```
4040

4141
## Error 3
42-
Description: Sizes must be of type `Array` unless breakpoints have been specified
43-
44-
45-
## Error 4
4642
Description: An ad must be passed into the GenericPlugin class. If your Plugin inherits from GenericPlugin
4743
and overrides the constructor make sure you are calling "super" and that you are passing in an
4844
instance of an ad as the first parameter. Alternatively, you can hook into the onCreate method
@@ -69,19 +65,23 @@ Description: An ad must be passed into the GenericPlugin class. If your Plugin i
6965
}
7066
```
7167

72-
## Error 5
68+
## Error 4
7369
Description: Parent element required for sticky plugin.
7470

7571

76-
## Error 6
72+
## Error 5
7773
Description: Ad does not have an id
7874

7975

80-
## Error 7
76+
## Error 6
8177
Description: Sizes must be defined.
8278

8379

84-
## Error 8
80+
## Error 7
8581
Description: Ad Path must be defined.
8682

83+
84+
## Error 8
85+
Description: Sizes must be of type `Array` unless breakpoints have been specified
86+
8787

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adjs",
3-
"version": "2.0.0-beta.29",
3+
"version": "2.0.0-beta.30",
44
"description": "Ad Library to simplify and optimize integration with ad networks such as DFP",
55
"main": "./core.js",
66
"types": "./types.d.ts",

src/networks/DFP.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DfpAd implements INetworkInstance {
1919

2020
const {
2121
el: { id },
22-
configuration: { sizes, targeting, path, breakpoints },
22+
configuration: { sizes, targeting, path, breakpoints, collapsible },
2323
} = ad;
2424

2525
if (!id) {
@@ -39,7 +39,11 @@ class DfpAd implements INetworkInstance {
3939
this.breakpoints = breakpoints;
4040

4141
googletag.cmd.push(() => {
42-
this.slot = googletag.defineSlot(path, Array.isArray(sizes) ? sizes : [0, 0], this.id);
42+
this.slot = googletag.defineSlot(path, Array.isArray(sizes) ? sizes : [0, 0], this.id);
43+
44+
if (collapsible) {
45+
this.slot.setCollapseEmptyDiv(true, true);
46+
}
4347

4448
if (targeting) {
4549
Object.entries(targeting)

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export interface IAdConfiguration {
165165
autoRender?: boolean;
166166
sticky?: boolean;
167167
enableByScroll?: boolean;
168+
collapsible?: boolean;
168169
clearOnExitViewport?: boolean;
169170
breakpoints?: IAdBreakpoints;
170171
offset?: number;

tests/ad.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Ad', () => {
2626
targeting: {
2727
newValues: 'moreTrue',
2828
},
29+
collapsible: true,
2930
};
3031

3132
const expected = {
@@ -35,6 +36,7 @@ describe('Ad', () => {
3536
newValues: 'moreTrue'
3637
},
3738
someNewKey: 'true',
39+
collapsible: true,
3840
};
3941

4042
const ad = page.createAd(el, overrides);

0 commit comments

Comments
 (0)