-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relevant Yield analytics adapter (#6195)
- Loading branch information
1 parent
a926dee
commit 524efda
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |