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

Relevant Yield analytics adapter #6195

Merged
merged 1 commit into from
Jan 28, 2021
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
33 changes: 33 additions & 0 deletions modules/relevantAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';

const relevantAnalytics = adapter({ analyticsType: 'bundle', handler: 'on' });

const { enableAnalytics: orgEnableAnalytics } = relevantAnalytics;

Object.assign(relevantAnalytics, {
/**
* Save event in the global array that will be consumed later by the Relevant Yield library
*/
track: ({ eventType: ev, args }) => {
window.relevantDigital.pbEventLog.push({ ev, args, ts: new Date() });
},

/**
* Before forwarding the call to the original enableAnalytics function -
* create (if needed) the global array that is used to pass events to the Relevant Yield library
* by the 'track' function above.
*/
enableAnalytics: function(...args) {
window.relevantDigital = window.relevantDigital || {};
window.relevantDigital.pbEventLog = window.relevantDigital.pbEventLog || [];
return orgEnableAnalytics.call(this, ...args);
},
});

adapterManager.registerAnalyticsAdapter({
adapter: relevantAnalytics,
code: 'relevant',
});

export default relevantAnalytics;
13 changes: 13 additions & 0 deletions modules/relevantAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Overview

Module Name: Relevant Yield Analytics Adapter

Module Type: Analytics Adapter

Maintainer: [support@relevant-digital.com](mailto:support@relevant-digital.com)

# Description

Analytics adapter to be used with [Relevant Yield](https://www.relevant-digital.com/relevantyield)

Contact [sales@relevant-digital.com](mailto:sales@relevant-digital.com) for information.
43 changes: 43 additions & 0 deletions test/spec/modules/relevantAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import relevantAnalytics from '../../../modules/relevantAnalyticsAdapter.js';
import adapterManager from 'src/adapterManager';
import events from 'src/events';
import constants from 'src/constants.json'
import { expect } from 'chai';

describe('Relevant Analytics Adapter', () => {
beforeEach(() => {
adapterManager.enableAnalytics({
provider: 'relevant'
});
});

afterEach(() => {
relevantAnalytics.disableAnalytics();
});

it('should pass all events to the global array', () => {
// Given
const testEvents = [
{ ev: constants.EVENTS.AUCTION_INIT, args: { test: 1 } },
{ ev: constants.EVENTS.BID_REQUESTED, args: { test: 2 } },
];

// When
testEvents.forEach(({ ev, args }) => (
events.emit(ev, args)
));

// Then
const eventQueue = (window.relevantDigital || {}).pbEventLog;
expect(eventQueue).to.be.an('array');
expect(eventQueue.length).to.be.at.least(testEvents.length);

// The last events should be our test events
const myEvents = eventQueue.slice(-testEvents.length);
testEvents.forEach(({ ev, args }, idx) => {
const actualEvent = myEvents[idx];
expect(actualEvent.ev).to.eql(ev);
expect(actualEvent.args).to.eql(args);
});
});
});