Skip to content

Commit

Permalink
2.0.1 - BugFix - Prebid Register Ad Toggle #68
Browse files Browse the repository at this point in the history
  • Loading branch information
Neal Malkani authored Oct 6, 2020
2 parents 82146e9 + 5f40ec1 commit a31ffd4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 42 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ To get started you must include the script tag for ArcAds in your page header, l
<script type="text/javascript">
const arcAds = new ArcAds({
dfp: {
id: '123'
id: '123',
collapseEmptyDivs: true
}
})
</script>
```

`collapseEmptyDivs` is an optional parameter that directly toggles `googletag.pubads().collapseEmptyDivs()`

Additionally, you can install the package with npm. This is mostly useful for when you're integrating ArcAds into a single page application or a JavaScript heavy project. Most implementations should just include the script in the page header.

```
Expand Down Expand Up @@ -217,7 +220,7 @@ If you'd like to include Prebid.js you must include the library before `arcads.j
</script>

```
You can enable Prebid.js on the wrapper by adding a `prebid` object to the wrapper initialization and setting `enabled: true`. You can also optionally pass it a `timeout` value which corresponds in milliseconds how long Prebid.js will wait until it closes out the bidding for the advertisements on the page. By default, the timeout will be set to `700`.
You can enable Prebid.js on the wrapper by adding a `prebid` object to the wrapper initialization and setting `enabled: true`. If `enabled` is `undefined`, `prebid` can still be used by providing a valid `bids` object. You can also optionally pass it a `timeout` value which corresponds in milliseconds how long Prebid.js will wait until it closes out the bidding for the advertisements on the page. By default, the timeout will be set to `700`.

```javascript
const arcAds = new ArcAds({
Expand Down
2 changes: 1 addition & 1 deletion dist/arcads.js

Large diffs are not rendered by default.

46 changes: 13 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arcads",
"version": "2.0.0",
"version": "2.0.1",
"description": "ArcAds is a DFP wrapper created by Arc Publishing with publishers in mind.",
"main": "dist/arcads.js",
"scripts": {
Expand Down
23 changes: 19 additions & 4 deletions src/__tests__/registerAds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('registerAds dimensions branches', () => {
expect(displayAdBindMock).toHaveBeenCalledWith(expectedArg1, expectedArg2);

});

it('should add two level dimensions appropriately', () => {

const adParams = {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('registerAds dimensions branches', () => {
targeting:{},
adType: true,
display: 'mobile',
bidding:{prebid:{bids:['bid1']}}
bidding:{prebid:{enabled: true, bids:['bid1']}}
}

const mobileAny = jest.fn().mockReturnValue(true);
Expand All @@ -169,7 +169,7 @@ describe('registerAds dimensions branches', () => {
expect(displayAdBindMock).toHaveBeenCalledTimes(1);
const expectedArg2 = {
"adType": true,
"bidding": {"prebid": {"bids": ["bid1"]}},
"bidding": {"prebid": {"enabled": true, "bids": ["bid1"]}},
"dimensions": [[[100, 50]]],
"display": "mobile",
"id": "testID",
Expand All @@ -179,6 +179,21 @@ describe('registerAds dimensions branches', () => {
expect(displayAdBindMock.mock.calls[0][1]).toEqual( expectedArg2);
});

it('prebid should not be called', () => {
const adParams = {
id: "testID",
slotname: "testSlotname",
dimensions: [[[100,50]]],
targeting:{},
adType: true,
display: 'mobile',
bidding:{prebid:{enabled: false, bids:['bid1']}}
}

arcAds.registerAd(adParams);
expect(addUnitMock).toHaveBeenCalledTimes(0);
});

it('wrapper has useSlotForAdUnit for caclulating prebid code', () => {
arcAds.wrapper = {
amazon: {
Expand All @@ -197,7 +212,7 @@ describe('registerAds dimensions branches', () => {
targeting:{},
adType: true,
display: 'mobile',
bidding:{prebid:{bids:['bid1']}}
bidding:{prebid:{enabled: true, bids:['bid1']}}
}

const mobileAny = jest.fn().mockReturnValue(true);
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ export class ArcAds {
Object.assign(params, { targeting: positionParam });
}

const prebidEnabled = bidding.prebid &&
((bidding.prebid.enabled && bidding.prebid.bids) ||
(typeof bidding.prebid.enabled === 'undefined' && bidding.prebid.bids));

if ((isMobile.any() && display === 'mobile') || (!isMobile.any() && display === 'desktop') || (display === 'all')) {
// Registers the advertisement with Prebid.js if enabled on both the unit and wrapper.
if ((bidding.prebid && bidding.prebid.bids) && (this.wrapper.prebid && this.wrapper.prebid.enabled) && flatDimensions) {
if (prebidEnabled && (this.wrapper.prebid && this.wrapper.prebid.enabled) && flatDimensions) {
if (pbjs && iframeBidders.length > 0) {
pbjs.setConfig({
userSync: {
Expand Down

0 comments on commit a31ffd4

Please sign in to comment.