Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit event when setTargetingForGPTAsync is called #873

Merged
merged 5 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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