forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZetaGlobal SSP Analytics Adapter: add new analytics adapter (prebid#7790
- Loading branch information
1 parent
527de82
commit 245e2d8
Showing
3 changed files
with
548 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,97 @@ | ||
import { logInfo, logError } from '../src/utils.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
import adapterManager from '../src/adapterManager.js'; | ||
import CONSTANTS from '../src/constants.json'; | ||
|
||
import adapter from '../src/AnalyticsAdapter.js'; | ||
|
||
const ZETA_GVL_ID = 833; | ||
const ADAPTER_CODE = 'zeta_global_ssp'; | ||
const BASE_URL = 'https://ssp.disqus.com/prebid/event'; | ||
const LOG_PREFIX = 'ZetaGlobalSsp-Analytics: '; | ||
|
||
/// /////////// VARIABLES //////////////////////////////////// | ||
|
||
let publisherId; // int | ||
|
||
/// /////////// HELPER FUNCTIONS ///////////////////////////// | ||
|
||
function sendEvent(eventType, event) { | ||
ajax( | ||
BASE_URL + '/' + eventType, | ||
null, | ||
JSON.stringify(event) | ||
); | ||
} | ||
|
||
/// /////////// ADAPTER EVENT HANDLER FUNCTIONS ////////////// | ||
|
||
function adRenderSucceededHandler(args) { | ||
let eventType = CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED | ||
logInfo(LOG_PREFIX + 'handle ' + eventType + ' event'); | ||
|
||
sendEvent(eventType, args); | ||
} | ||
|
||
function auctionEndHandler(args) { | ||
let eventType = CONSTANTS.EVENTS.AUCTION_END; | ||
logInfo(LOG_PREFIX + 'handle ' + eventType + ' event'); | ||
|
||
sendEvent(eventType, args); | ||
} | ||
|
||
/// /////////// ADAPTER DEFINITION /////////////////////////// | ||
|
||
let baseAdapter = adapter({ analyticsType: 'endpoint' }); | ||
let zetaAdapter = Object.assign({}, baseAdapter, { | ||
|
||
enableAnalytics(config = {}) { | ||
let error = false; | ||
|
||
if (typeof config.options === 'object') { | ||
if (config.options.sid) { | ||
publisherId = Number(config.options.sid); | ||
} | ||
} else { | ||
logError(LOG_PREFIX + 'Config not found'); | ||
error = true; | ||
} | ||
|
||
if (!publisherId) { | ||
logError(LOG_PREFIX + 'Missing sid (publisher id)'); | ||
error = true; | ||
} | ||
|
||
if (error) { | ||
logError(LOG_PREFIX + 'Analytics is disabled due to error(s)'); | ||
} else { | ||
baseAdapter.enableAnalytics.call(this, config); | ||
} | ||
}, | ||
|
||
disableAnalytics() { | ||
publisherId = undefined; | ||
baseAdapter.disableAnalytics.apply(this, arguments); | ||
}, | ||
|
||
track({ eventType, args }) { | ||
switch (eventType) { | ||
case CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED: | ||
adRenderSucceededHandler(args); | ||
break; | ||
case CONSTANTS.EVENTS.AUCTION_END: | ||
auctionEndHandler(args); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
/// /////////// ADAPTER REGISTRATION ///////////////////////// | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: zetaAdapter, | ||
code: ADAPTER_CODE, | ||
gvlid: ZETA_GVL_ID | ||
}); | ||
|
||
export default zetaAdapter; |
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,24 @@ | ||
# Zeta Global SSP Analytics Adapter | ||
|
||
## Overview | ||
|
||
Module Name: Zeta Global SSP Analytics Adapter\ | ||
Module Type: Analytics Adapter\ | ||
Maintainer: abermanov@zetaglobal.com | ||
|
||
## Description | ||
|
||
Analytics Adapter which sends auctionEnd and adRenderSucceeded events to Zeta Global SSP analytics endpoints | ||
|
||
## How to configure | ||
``` | ||
pbjs.enableAnalytics({ | ||
provider: 'zeta_global_ssp', | ||
options: { | ||
sid: 111, | ||
tags: { | ||
... | ||
} | ||
} | ||
}); | ||
``` |
Oops, something went wrong.