-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
IntentIQ Analytics Adapter: initial release #11930
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c85483f
IntentIQ Analytics Module
DimaIntentIQ ca9dc75
Merge branch 'prebid:master' into iiq_analytic_adapter
eyvazahmadzada a60f5ec
update intentiq analytics adapter
eyvazahmadzada e4f9c5a
remove percentage and change group
eyvazahmadzada 0583ebe
update analytics adapter and tests
eyvazahmadzada 119b244
updated flow
DimaIntentIQ a8947af
remove 'this'
DimaIntentIQ 7bb6983
rename privacy parameter
DimaIntentIQ ce17746
add callback timeout
DimaIntentIQ fefca12
Extract only used parameters from CryptoJS
DimaIntentIQ 1033bdd
add new unit tests
eyvazahmadzada 02ec975
change callback timeout order
DimaIntentIQ 5cb3c88
added tests and small fixes
eyvazahmadzada c3da09d
change saving logic
DimaIntentIQ 9ab9f14
support "html5" and "cookie" storage types
DimaIntentIQ 41cc517
support storage type, update flow
DimaIntentIQ 684e7fa
add documentation
DimaIntentIQ 2a034a9
small updates
DimaIntentIQ fec51df
IntentIQ Analytics Module
DimaIntentIQ 33c36b2
Multiple modules: clean up unit tests (#11630)
dgirardi b204973
update intentiq analytics adapter
eyvazahmadzada 8f46a3b
undo unnecessary changes
eyvazahmadzada 7c13417
undo change by mistake
eyvazahmadzada 75b04f3
Merge branch 'master' into iiq_analytic_adapter
DimaIntentIQ 424ab9f
update params and documentation
DimaIntentIQ 3397198
Merge pull request #1 from DimaIntentIQ/update_params
DimaIntentIQ 3f443af
turn back storage clearing
DimaIntentIQ eecec04
fix linter error
DimaIntentIQ fc72fe7
fix wording and spelling mistakes
eyvazahmadzada e4d71c7
change test to handle full url to check other ids not reported
eyvazahmadzada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,234 @@ | ||
import { logInfo, logError } from '../src/utils.js'; | ||
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'; | ||
import adapterManager from '../src/adapterManager.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
import { config } from '../src/config.js'; | ||
import { EVENTS } from '../src/constants.js'; | ||
import { MODULE_TYPE_ANALYTICS } from '../src/activities/modules.js'; | ||
|
||
const MODULE_NAME = 'iiqAnalytics' | ||
const analyticsType = 'endpoint'; | ||
const defaultUrl = 'https://reports.intentiq.com/report'; | ||
const storage = getStorageManager({ moduleType: MODULE_TYPE_ANALYTICS, moduleName: MODULE_NAME }); | ||
const prebidVersion = '$prebid.version$'; | ||
const REPORTER_ID = Date.now() + '_' + getRandom(0, 1000); | ||
|
||
const FIRST_PARTY_KEY = '_iiq_fdata'; | ||
const FIRST_PARTY_DATA_KEY = '_iiq_fdata'; | ||
const JSVERSION = 0.1 | ||
|
||
const PARAMS_NAMES = { | ||
abTestGroup: 'abGroup', | ||
pbPauseUntil: 'pbPauseUntil', | ||
pbMonitoringEnabled: 'pbMonitoringEnabled', | ||
isInTestGroup: 'isInTestGroup', | ||
enhanceRequests: 'enhanceRequests', | ||
wasSubscribedForPrebid: 'wasSubscribedForPrebid', | ||
hadEids: 'hadEids', | ||
ABTestingConfigurationSource: 'ABTestingConfigurationSource', | ||
lateConfiguration: 'lateConfiguration', | ||
jsversion: 'jsversion', | ||
eidsNames: 'eidsNames', | ||
requestRtt: 'rtt', | ||
clientType: 'clientType', | ||
adserverDeviceType: 'AdserverDeviceType', | ||
terminationCause: 'terminationCause', | ||
callCount: 'callCount', | ||
manualCallCount: 'mcc', | ||
pubprovidedidsFailedToregister: 'ppcc', | ||
noDataCount: 'noDataCount', | ||
profile: 'profile', | ||
isProfileDeterministic: 'pidDeterministic', | ||
siteId: 'sid', | ||
hadEidsInLocalStorage: 'idls', | ||
auctionStartTime: 'ast', | ||
eidsReadTime: 'eidt', | ||
agentId: 'aid', | ||
auctionEidsLength: 'aeidln', | ||
wasServerCalled: 'wsrvcll', | ||
referrer: 'vrref', | ||
isInBrowserBlacklist: 'inbbl', | ||
prebidVersion: 'pbjsver', | ||
partnerId: 'partnerId' | ||
}; | ||
|
||
let iiqAnalyticsAnalyticsAdapter = Object.assign(adapter({ defaultUrl, analyticsType }), { | ||
initOptions: { | ||
lsValueInitialized: false, | ||
partner: null, | ||
fpid: null, | ||
currentGroup: null, | ||
dataInLs: null, | ||
eidl: null, | ||
lsIdsInitialized: false, | ||
manualReport: false | ||
}, | ||
track({ eventType, args }) { | ||
switch (eventType) { | ||
case BID_WON: | ||
bidWon(args); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
// Events needed | ||
const { | ||
BID_WON | ||
} = EVENTS; | ||
|
||
function readData(key) { | ||
try { | ||
if (storage.hasLocalStorage()) { | ||
return storage.getDataFromLocalStorage(key); | ||
} | ||
if (storage.cookiesAreEnabled()) { | ||
return storage.getCookie(key); | ||
} | ||
} catch (error) { | ||
logError(error); | ||
} | ||
} | ||
|
||
function initLsValues() { | ||
if (iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized) return; | ||
iiqAnalyticsAnalyticsAdapter.initOptions.fpid = JSON.parse(readData(FIRST_PARTY_KEY)); | ||
let iiqArr = config.getConfig('userSync.userIds').filter(m => m.name == 'intentIqId'); | ||
if (iiqArr && iiqArr.length > 0) iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized = true; | ||
if (!iiqArr) iiqArr = []; | ||
if (iiqArr.length == 0) { | ||
iiqArr.push({ | ||
'params': { | ||
'partner': -1, | ||
'group': 'U' | ||
} | ||
}) | ||
} | ||
if (iiqArr && iiqArr.length > 0) { | ||
if (iiqArr[0].params && iiqArr[0].params.partner && !isNaN(iiqArr[0].params.partner)) { | ||
iiqAnalyticsAnalyticsAdapter.initOptions.partner = iiqArr[0].params.partner; | ||
iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup = iiqAnalyticsAnalyticsAdapter.initOptions.fpid.group; | ||
} | ||
} | ||
} | ||
|
||
function initReadLsIds() { | ||
if (isNaN(iiqAnalyticsAnalyticsAdapter.initOptions.partner) || iiqAnalyticsAnalyticsAdapter.initOptions.partner == -1) return; | ||
try { | ||
iiqAnalyticsAnalyticsAdapter.initOptions.dataInLs = null; | ||
let iData = readData(FIRST_PARTY_DATA_KEY + '_' + iiqAnalyticsAnalyticsAdapter.initOptions.partner) | ||
if (iData) { | ||
iiqAnalyticsAnalyticsAdapter.initOptions.lsIdsInitialized = true; | ||
let pData = JSON.parse(iData); | ||
iiqAnalyticsAnalyticsAdapter.initOptions.dataInLs = pData.data; | ||
iiqAnalyticsAnalyticsAdapter.initOptions.eidl = pData.eidl || -1; | ||
} | ||
} catch (e) { | ||
logError(e) | ||
} | ||
} | ||
|
||
function bidWon(args) { | ||
if (!iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized) { initLsValues(); } | ||
if (iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized && !iiqAnalyticsAnalyticsAdapter.initOptions.lsIdsInitialized) { initReadLsIds(); } | ||
if (!iiqAnalyticsAnalyticsAdapter.initOptions.manualReport) { | ||
ajax(constructFullUrl(preparePayload(args, true)), undefined, null, { method: 'GET' }); | ||
} | ||
|
||
logInfo('IIQ ANALYTICS -> BID WON') | ||
} | ||
|
||
function getRandom(start, end) { | ||
return Math.floor((Math.random() * (end - start + 1)) + start); | ||
} | ||
|
||
function preparePayload(data) { | ||
let result = getDefaultDataObject(); | ||
|
||
result[PARAMS_NAMES.partnerId] = iiqAnalyticsAnalyticsAdapter.initOptions.partner; | ||
result[PARAMS_NAMES.prebidVersion] = prebidVersion; | ||
result[PARAMS_NAMES.referrer] = getReferrer(); | ||
|
||
result[PARAMS_NAMES.abTestGroup] = iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup; | ||
|
||
result[PARAMS_NAMES.isInTestGroup] = iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup == 'A'; | ||
|
||
result[PARAMS_NAMES.agentId] = REPORTER_ID; | ||
|
||
fillPrebidEventData(data, result); | ||
|
||
fillEidsData(result); | ||
|
||
return result; | ||
} | ||
|
||
function fillEidsData(result) { | ||
if (iiqAnalyticsAnalyticsAdapter.initOptions.lsIdsInitialized) { | ||
result[PARAMS_NAMES.hadEidsInLocalStorage] = iiqAnalyticsAnalyticsAdapter.initOptions.eidl && iiqAnalyticsAnalyticsAdapter.initOptions.eidl > 0; | ||
result[PARAMS_NAMES.auctionEidsLength] = iiqAnalyticsAnalyticsAdapter.initOptions.eidl || -1; | ||
} | ||
} | ||
|
||
function fillPrebidEventData(eventData, result) { | ||
if (eventData.bidderCode) { result.bidderCode = eventData.bidderCode; } | ||
if (eventData.cpm) { result.cpm = eventData.cpm; } | ||
if (eventData.currency) { result.currency = eventData.currency; } | ||
if (eventData.originalCpm) { result.originalCpm = eventData.originalCpm; } | ||
if (eventData.originalCurrency) { result.originalCurrency = eventData.originalCurrency; } | ||
if (eventData.status) { result.status = eventData.status; } | ||
if (eventData.auctionId) { result.prebidAuctionId = eventData.auctionId; } | ||
|
||
result.biddingPlatformId = 1; | ||
result.partnerAuctionId = 'BW'; | ||
} | ||
|
||
function getDefaultDataObject() { | ||
return { | ||
'inbbl': false, | ||
'pbjsver': prebidVersion, | ||
'partnerAuctionId': 'BW', | ||
'reportSource': 'pbjs', | ||
'abGroup': 'U', | ||
'jsversion': JSVERSION, | ||
'partnerId': -1, | ||
'biddingPlatformId': 1, | ||
'idls': false, | ||
'ast': -1, | ||
'aeidln': -1 | ||
} | ||
} | ||
|
||
function constructFullUrl(data) { | ||
let report = [] | ||
data = btoa(JSON.stringify(data)) | ||
report.push(data) | ||
return defaultUrl + '?pid=' + iiqAnalyticsAnalyticsAdapter.initOptions.partner + | ||
'&mct=1' + | ||
((iiqAnalyticsAnalyticsAdapter.initOptions && iiqAnalyticsAnalyticsAdapter.initOptions.fpid) | ||
? '&iiqid=' + encodeURIComponent(iiqAnalyticsAnalyticsAdapter.initOptions.fpid.pcid) : '') + | ||
'&agid=' + REPORTER_ID + | ||
'&jsver=' + JSVERSION + | ||
'&vrref=' + getReferrer() + | ||
'&source=pbjs' + | ||
'&payload=' + JSON.stringify(report) | ||
} | ||
|
||
function getReferrer() { | ||
return document.referrer; | ||
} | ||
|
||
iiqAnalyticsAnalyticsAdapter.originEnableAnalytics = iiqAnalyticsAnalyticsAdapter.enableAnalytics; | ||
|
||
iiqAnalyticsAnalyticsAdapter.enableAnalytics = function (myConfig) { | ||
iiqAnalyticsAnalyticsAdapter.originEnableAnalytics(myConfig); // call the base class function | ||
}; | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: iiqAnalyticsAnalyticsAdapter, | ||
code: MODULE_NAME | ||
}); | ||
|
||
export default iiqAnalyticsAnalyticsAdapter; |
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,27 @@ | ||
# Overview | ||
|
||
Module Name: iiqAnalytics | ||
Module Type: Analytics Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
By using this Intent IQ adapter, you will be able to obtain comprehensive analytics and metrics regarding the performance of the Intent IQ Unified ID module. This includes how the module impacts your revenue, CPMs, and fill rates related to bidders and domains. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your customers may prefer a sampling rate parameter; analytics can be a drag. |
||
|
||
## Intent IQ Universal ID Registration | ||
|
||
No registration for this module is required. | ||
|
||
## Intent IQ Universal IDConfiguration | ||
|
||
<B>IMPORTANT</B>: only effective when Intent IQ Universal ID module is installed and configured. [(How-To)](https://docs.prebid.org/dev-docs/modules/userid-submodules/intentiq.html) | ||
|
||
No additional configuration for this module is required. We will use the configuration provided for Intent IQ Universal IQ module. | ||
|
||
#### Example Configuration | ||
|
||
```js | ||
pbjs.enableAnalytics({ | ||
provider: 'iiqAnalytics' | ||
}); | ||
``` |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some friendly advice, your get requests are going to run out of characters and you'll eventually want to switch to post one day. the sooner you do, the less painful it will be for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, if you pass options = keepalive, the page performance will be better and you'll be more likely to get the events after the page dies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the suggestion, @patmmccann! Yes, we're planning to implement these in the next updates. We would like to get the adapter approved and merged first.