From d4f7d81f525a67c3ecad1713449b9bcfd49c7419 Mon Sep 17 00:00:00 2001 From: Stanislav Golikov Date: Thu, 31 Oct 2024 19:26:00 +0300 Subject: [PATCH] Added init event for yandexAnalyticsAdapter (#12386) --- modules/yandexAnalyticsAdapter.js | 5 +++ .../modules/yandexAnalyticsAdapter_spec.js | 37 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/modules/yandexAnalyticsAdapter.js b/modules/yandexAnalyticsAdapter.js index 8afe7298c13..6c44bea7cd2 100644 --- a/modules/yandexAnalyticsAdapter.js +++ b/modules/yandexAnalyticsAdapter.js @@ -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) => { @@ -23,6 +24,7 @@ const clearTryUntilTimeouts = (timeouts) => { }); }; +export const PBJS_INIT_EVENT_NAME = 'pbjsInit'; const SEND_EVENTS_BUNDLE_TIMEOUT = 1500; const { BID_REQUESTED, @@ -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); diff --git a/test/spec/modules/yandexAnalyticsAdapter_spec.js b/test/spec/modules/yandexAnalyticsAdapter_spec.js index ca9b29d13a5..a7a850b7cf2 100644 --- a/test/spec/modules/yandexAnalyticsAdapter_spec.js +++ b/test/spec/modules/yandexAnalyticsAdapter_spec.js @@ -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(); @@ -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 = {}; @@ -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'); @@ -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: { @@ -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: {}, + } + ]); }); });