Skip to content

Commit 187bf9d

Browse files
committed
Added option to toggle url-targeting parameters
1 parent b7ca4bb commit 187bf9d

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

jquery.dfp.js

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@
6565
*/
6666
setOptions = function (options) {
6767

68-
// Get URL Targeting
69-
var URLTargets = getURLTargets();
70-
7168
// Set default options
7269
dfpOptions = {
73-
setTargeting: {
74-
inURL: URLTargets.inURL,
75-
URLIs: URLTargets.URLIs,
76-
Query: URLTargets.Query,
77-
Domain: window.location.host
78-
},
70+
setTargeting: {},
7971
setCategoryExclusion: '',
8072
enableSingleRequest: true,
8173
collapseEmptyDivs: 'original',
82-
targetPlatform: 'web',
83-
enableSyncRendering: false,
84-
refreshExisting: true
74+
refreshExisting: true,
75+
disablePublisherConsole: false,
76+
disableInitialLoad: false,
77+
noFetch: false,
8578
};
8679

80+
if (typeof (options.setUrlTargeting) == 'undefined' || options.setUrlTargeting)
81+
{
82+
// Get URL Targeting
83+
var urlTargeting = getUrlTargeting();
84+
$.extend(true, dfpOptions.setTargeting, { inURL: urlTargeting.inURL, URLIs: urlTargeting.URLIs, Query: urlTargeting.Query, Domain: window.location.host });
85+
}
86+
8787
// Merge options objects
8888
$.extend(true, dfpOptions, options);
8989

@@ -93,7 +93,6 @@
9393
$.extend(true, window.googletag, dfpOptions.googletag);
9494
});
9595
}
96-
9796
},
9897

9998
/**
@@ -228,6 +227,19 @@
228227
if (dfpOptions.collapseEmptyDivs === true || dfpOptions.collapseEmptyDivs === 'original') {
229228
window.googletag.pubads().collapseEmptyDivs();
230229
}
230+
231+
if (dfpOptions.disablePublisherConsole === true) {
232+
window.googletag.pubads().disablePublisherConsole();
233+
}
234+
235+
if (dfpOptions.disableInitialLoad === true) {
236+
window.googletag.pubads().disableInitialLoad();
237+
}
238+
239+
if (dfpOptions.noFetch === true) {
240+
window.googletag.pubads().noFetch();
241+
}
242+
231243
window.googletag.enableServices();
232244

233245
});
@@ -263,7 +275,7 @@
263275
* Create an array of paths so that we can target DFP ads to Page URI's
264276
* @return Array an array of URL parts that can be targeted.
265277
*/
266-
getURLTargets = function () {
278+
getUrlTargeting = function () {
267279

268280
// Get the paths for targeting against
269281
var paths = window.location.pathname.replace(/\/$/, ''),
@@ -417,6 +429,15 @@
417429
// SetTimeout is a bit dirty but the script does not execute in the correct order without it
418430
setTimeout(function () {
419431

432+
var _defineSlot = function(name, dimensions, id, oop) {
433+
window.googletag.ads.push(id);
434+
window.googletag.ads[id] = {
435+
renderEnded: function() { },
436+
addService: function() { return this; }
437+
};
438+
return window.googletag.ads[id];
439+
};
440+
420441
// overwrite the dfp object - replacing the command array with a function and defining missing functions
421442
window.googletag = {
422443
cmd: {
@@ -426,25 +447,18 @@
426447
},
427448
ads: [],
428449
pubads: function () { return this; },
450+
noFetch:function () { return this; },
451+
disableInitialLoad: function () { return this; },
452+
disablePublisherConsole: function () { return this; },
429453
enableSingleRequest: function () { return this; },
430454
setTargeting: function () { return this; },
431455
collapseEmptyDivs: function () { return this; },
432456
enableServices: function () { return this; },
433-
defineSlot: function (name, dimensions, id) {
434-
window.googletag.ads.push(id);
435-
window.googletag.ads[id] = {
436-
renderEnded: function () {},
437-
addService: function () { return this; }
438-
};
439-
return window.googletag.ads[id];
457+
defineSlot: function(name, dimensions, id) {
458+
return _defineSlot(name, dimensions, id, false);
440459
},
441460
defineOutOfPageSlot: function (name, id) {
442-
window.googletag.ads.push(id);
443-
window.googletag.ads[id] = {
444-
renderEnded: function () {},
445-
addService: function () { return this; }
446-
};
447-
return window.googletag.ads[id];
461+
return _defineSlot(name, [], id, true);
448462
},
449463
display: function (id) {
450464
window.googletag.ads[id].renderEnded.call(dfpScript);

tests/spec/targetingSpec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,42 @@ describe("Targeting", function () {
5050

5151
});
5252

53+
it("URL Targeting options are not set (page)", function () {
54+
55+
var mock = {};
56+
mock.setTargeting = function (param) { };
57+
58+
var dummyTag = {};
59+
dummyTag.pubads = function () {
60+
return {
61+
enableSingleRequest: function () { },
62+
setTargeting: mock.setTargeting,
63+
collapseEmptyDivs: function () { }
64+
};
65+
};
66+
67+
spyOn(mock, "setTargeting").andCallThrough();
68+
69+
runs(function () {
70+
jQuery.dfp({
71+
dfpID: 'xxxxxxxxx',
72+
setUrlTargeting: false,
73+
googletag: dummyTag
74+
});
75+
}, "Kick off loader");
76+
77+
waitsFor(function () {
78+
if (typeof window.googletag.getVersion === 'function') {
79+
return true;
80+
} else {
81+
return false;
82+
}
83+
}, "getVersion function to exist", 5000);
84+
85+
runs(function () {
86+
expect(mock.setTargeting).not.toHaveBeenCalled();
87+
});
88+
89+
});
90+
5391
});

0 commit comments

Comments
 (0)