Skip to content

Commit

Permalink
Added init event for yandexAnalyticsAdapter (#12386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislavsky34200 authored Oct 31, 2024
1 parent 0209218 commit d4f7d81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions modules/yandexAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import adapterManager from '../src/adapterManager.js';
import { logError, logInfo } from '../src/utils.js';
import { EVENTS } from '../src/constants.js';
import * as events from '../src/events.js';
import { getGlobal } from '../src/prebidGlobal.js';

const timeoutIds = {};
const tryUntil = (operationId, conditionCb, cb) => {
Expand All @@ -23,6 +24,7 @@ const clearTryUntilTimeouts = (timeouts) => {
});
};

export const PBJS_INIT_EVENT_NAME = 'pbjsInit';
const SEND_EVENTS_BUNDLE_TIMEOUT = 1500;
const {
BID_REQUESTED,
Expand Down Expand Up @@ -122,6 +124,9 @@ const yandexAnalytics = Object.assign(buildAdapter({ analyticsType: 'endpoint' }
logError('Aborting yandex analytics provider initialization.');
}, 25000);

yandexAnalytics.onEvent(PBJS_INIT_EVENT_NAME, {
'version': getGlobal().version,
});
events.getEvents().forEach((event) => {
if (event && EVENTS_TO_TRACK.indexOf(event.eventType) >= 0) {
yandexAnalytics.onEvent(event.eventType, event);
Expand Down
37 changes: 27 additions & 10 deletions test/spec/modules/yandexAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as sinon from 'sinon';
import yandexAnalytics, { EVENTS_TO_TRACK } from 'modules/yandexAnalyticsAdapter.js';
import yandexAnalytics, { EVENTS_TO_TRACK, PBJS_INIT_EVENT_NAME } from 'modules/yandexAnalyticsAdapter.js';
import * as log from '../../../src/utils.js'
import * as events from '../../../src/events.js';
import * as globalUtils from '../../../src/prebidGlobal.js';

describe('Yandex analytics adapter testing', () => {
const sandbox = sinon.createSandbox();
Expand All @@ -11,6 +12,13 @@ describe('Yandex analytics adapter testing', () => {
let onEvent;
const counterId = 123;
const counterWindowKey = 'yaCounter123';
const prebidVersion = '123.0';
const prebidInitEvent = {
event: PBJS_INIT_EVENT_NAME,
data: {
version: prebidVersion,
},
}

beforeEach(() => {
yandexAnalytics.counters = {};
Expand All @@ -19,6 +27,9 @@ describe('Yandex analytics adapter testing', () => {
yandexAnalytics.oneCounterInited = false;
clock = sinon.useFakeTimers();
logError = sandbox.stub(log, 'logError');
sandbox.stub(globalUtils, 'getGlobal').returns({
version: prebidVersion,
});
sandbox.stub(log, 'logInfo');
getEvents = sandbox.stub(events, 'getEvents').returns([]);
onEvent = sandbox.stub(events, 'on');
Expand Down Expand Up @@ -86,12 +97,15 @@ describe('Yandex analytics adapter testing', () => {
eventType: 'Some_untracked_event',
}
]);
const eventsToSend = [{
event: EVENTS_TO_TRACK[0],
data: {
eventType: EVENTS_TO_TRACK[0],
const eventsToSend = [
prebidInitEvent,
{
event: EVENTS_TO_TRACK[0],
data: {
eventType: EVENTS_TO_TRACK[0],
}
}
}];
];

yandexAnalytics.enableAnalytics({
options: {
Expand Down Expand Up @@ -139,9 +153,12 @@ describe('Yandex analytics adapter testing', () => {
clock.tick(2001);

const [ sentEvents ] = counterPbjsMethod.getCall(0).args;
chai.expect(sentEvents).to.deep.equal([{
event,
data: {},
}]);
chai.expect(sentEvents).to.deep.equal([
prebidInitEvent,
{
event,
data: {},
}
]);
});
});

0 comments on commit d4f7d81

Please sign in to comment.