Skip to content

Commit

Permalink
Generic analytics: fix spurious warning messages (prebid#10739)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Nov 30, 2023
1 parent 9c597a3 commit a8fedc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions modules/genericAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AnalyticsAdapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import {prefixLog, isPlainObject} from '../src/utils.js';
import * as CONSTANTS from '../src/constants.json';
import {has as hasEvent} from '../src/events.js';
import adapterManager from '../src/adapterManager.js';
import {ajaxBuilder} from '../src/ajax.js';

Expand Down Expand Up @@ -48,12 +48,12 @@ export function GenericAnalytics() {
return false;
}
for (const [event, handler] of Object.entries(options.events)) {
if (!CONSTANTS.EVENTS.hasOwnProperty(event)) {
if (!hasEvent(event)) {
logWarn(`options.events.${event} does not match any known Prebid event`);
if (typeof handler !== 'function') {
logError(`options.events.${event} must be a function`);
return false;
}
}
if (typeof handler !== 'function') {
logError(`options.events.${event} must be a function`);
return false;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const _public = (function () {
return allEvents.includes(event)
}

_public.has = _checkAvailableEvent;

_public.on = function (eventString, handler, id) {
// check whether available event or not
if (_checkAvailableEvent(eventString)) {
Expand Down Expand Up @@ -163,7 +165,7 @@ const _public = (function () {

utils._setEventEmitter(_public.emit.bind(_public));

export const {on, off, get, getEvents, emit, addEvents} = _public;
export const {on, off, get, getEvents, emit, addEvents, has} = _public;

export function clearEvents() {
eventsFired.clear();
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/genericAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Generic analytics', () => {
options: {
url: 'mock',
events: {
bidResponse: null
mockEvent: null
}
}
});
Expand Down

0 comments on commit a8fedc6

Please sign in to comment.