Skip to content

Commit

Permalink
ZetaGlobal SSP Analytics Adapter: add new analytics adapter (prebid#7790
Browse files Browse the repository at this point in the history
)

* Zeta Global SSP Analytics Adapter

* Trigger the build

* Trigger the build
  • Loading branch information
abermanov-zeta authored and Chris Pabst committed Jan 10, 2022
1 parent 527de82 commit 245e2d8
Show file tree
Hide file tree
Showing 3 changed files with 548 additions and 0 deletions.
97 changes: 97 additions & 0 deletions modules/zeta_global_sspAnalyticsAdapter.js
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;
24 changes: 24 additions & 0 deletions modules/zeta_global_sspAnalyticsAdapter.md
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: {
...
}
}
});
```
Loading

0 comments on commit 245e2d8

Please sign in to comment.