Skip to content

Commit

Permalink
Emit event when setTargetingForGPTAsync is called (#873)
Browse files Browse the repository at this point in the history
* emitting event when setTargetingForGPTAsync is called

* emitting event when setTargetingForGPTAsync is called - cleanup

* emitting event when setTargetingForGPTAsync is called - cleanup
  • Loading branch information
itayo155 authored and jaiminpanchal27 committed Jan 19, 2017
1 parent 8303597 commit 65d1d22
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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() {
Expand All @@ -256,6 +261,9 @@ $$PREBID_GLOBAL$$.setTargetingForAst = function() {
}

targeting.setTargetingForAst();

//emit event
events.emit(SET_TARGETING);
};

/**
Expand Down
12 changes: 12 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 65d1d22

Please sign in to comment.