Skip to content

Commit

Permalink
Make it possible to load ads from multiple DFP accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
coop182 committed Sep 5, 2015
1 parent b4890e0 commit 77008ca
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.dfp",
"version": "2.1.0",
"version": "2.2.0",
"main": "jquery.dfp.js",
"ignore": [
"img/",
Expand Down
2 changes: 1 addition & 1 deletion dfp.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ads",
"advertising"
],
"version": "2.1.0",
"version": "2.2.0",
"author": {
"name": "Matt Cooper",
"email": "[email protected]",
Expand Down
14 changes: 11 additions & 3 deletions jquery.dfp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* jQuery DFP v2.1.0
* jQuery DFP v2.2.0
* http://github.com/coop182/jquery.dfp.js
*
* Copyright 2015 Matt Cooper
Expand Down Expand Up @@ -159,11 +159,19 @@

} else {

// Build slotName for loading
var slotName;
if (dfpID === '') {
slotName = adUnitName;
} else {
slotName = '/' + dfpID + '/' + adUnitName;
}

// Create the ad - out of page or normal
if ($adUnit.data('outofpage')) {
googleAdUnit = googletag.defineOutOfPageSlot('/' + dfpID + '/' + adUnitName, adUnitID);
googleAdUnit = googletag.defineOutOfPageSlot(slotName, adUnitID);
} else {
googleAdUnit = googletag.defineSlot('/' + dfpID + '/' + adUnitName, dimensions, adUnitID);
googleAdUnit = googletag.defineSlot(slotName, dimensions, adUnitID);
if ($adUnit.data('companion')) {
googleAdUnit = googleAdUnit.addService(googletag.companionAds());
}
Expand Down
4 changes: 2 additions & 2 deletions jquery.dfp.min.js

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": "jquery.dfp",
"version": "2.1.0",
"version": "2.2.0",
"devDependencies": {
"grunt": "~0.4",
"grunt-contrib-jasmine": "^0.8.2",
Expand Down
24 changes: 24 additions & 0 deletions tests/spec/adUnitSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ describe('Ad units', function () {
beforeEach(cleanup);
afterEach(cleanup);

it('Call to DFP with dfpID in adunit name', function (done) {
var id = 'xxxxxxx';

var dummyTag = {};
dummyTag.enableServices = function() {};

$('body').append('<div class="adunit" data-adunit="/' + id + '/Leader"></div>');
$.dfp({
googletag: dummyTag
});

waitsForAndRuns(function () {
if (typeof window.googletag.getVersion === 'function' && $('.adunit').data('googleAdUnit')) {
return true;
} else {
return false;
}
}, function () {
expect($('.adunit').data('googleAdUnit').getName()).toEqual('/' + id + '/Leader');
done();
}, 5000);

});

it('Auto generate an ID for the ad unit if no ID provided', function (done) {

var dummyTag = {};
Expand Down

0 comments on commit 77008ca

Please sign in to comment.