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

ZetaGlobal SSP Analytics Adapter: add new analytics adapter #7790

Merged
merged 3 commits into from
Dec 14, 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
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