diff --git a/src/constants.json b/src/constants.json index 4d029c87458..aa88fae3178 100644 --- a/src/constants.json +++ b/src/constants.json @@ -34,7 +34,8 @@ "BID_TIMEOUT": "bidTimeout", "BID_REQUESTED": "bidRequested", "BID_RESPONSE": "bidResponse", - "BID_WON": "bidWon" + "BID_WON": "bidWon", + "SET_TARGETING": "setTargeting" }, "EVENT_ID_PATHS": { "bidWon": "adUnitCode" diff --git a/src/prebid.js b/src/prebid.js index def4e2ff738..49cdf9d06c1 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -25,6 +25,7 @@ var objectType_function = 'function'; var objectType_undefined = 'undefined'; var objectType_object = 'object'; var BID_WON = CONSTANTS.EVENTS.BID_WON; +var SET_TARGETING = CONSTANTS.EVENTS.SET_TARGETING; var auctionRunning = false; var bidRequestQueue = []; @@ -244,8 +245,12 @@ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function () { //first reset any old targeting targeting.resetPresetTargeting(); + //now set new targeting keys targeting.setTargeting(targeting.getAllTargeting()); + + //emit event + events.emit(SET_TARGETING); }; $$PREBID_GLOBAL$$.setTargetingForAst = function() { @@ -256,6 +261,9 @@ $$PREBID_GLOBAL$$.setTargetingForAst = function() { } targeting.setTargetingForAst(); + + //emit event + events.emit(SET_TARGETING); }; /** diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 98538a5cd1a..c414ba1b8cb 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -483,6 +483,18 @@ describe('Unit: Prebid Module', function () { assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); window.googletag = windowGoogletagBackup; }); + + it('should emit SET_TARGETING event when successfully invoked', function() { + var slots = createSlotArray(); + window.googletag.pubads().setSlots(slots); + + var callback = sinon.spy(); + + $$PREBID_GLOBAL$$.onEvent('setTargeting', callback); + $$PREBID_GLOBAL$$.setTargetingForGPTAsync(config.adUnitCodes); + + sinon.assert.calledOnce(callback); + }) }); describe('allBidsAvailable', function () {