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

Platform One Analytics Adapter #4233

Merged
merged 7 commits into from
Oct 15, 2019
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
122 changes: 122 additions & 0 deletions modules/yieldoneAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {ajax} from '../src/ajax';
import adapter from '../src/AnalyticsAdapter';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager';
import { targeting } from '../src/targeting';
import { auctionManager } from '../src/auctionManager';
import * as utils from '../src/utils';

const ANALYTICS_CODE = 'yieldone';
const analyticsType = 'endpoint';
// const VERSION = '1.0.0';
const defaultUrl = '//pool.tsukiji.iponweb.net/hba';
const requestedBidders = {};
const requestedBids = {};
const referrers = {};

let currentAuctionId = '';
let url = defaultUrl;
let pubId = '';

const yieldoneAnalytics = Object.assign(adapter({analyticsType}), {
getUrl() { return url; },
track({eventType, args = {}}) {
if (eventType === CONSTANTS.EVENTS.BID_REQUESTED) {
const reqBidderId = `${args.bidderCode}_${args.auctionId}`;
requestedBidders[reqBidderId] = utils.deepClone(args);
requestedBidders[reqBidderId].bids = [];
args.bids.forEach((bid) => {
requestedBids[`${bid.bidId}_${bid.auctionId}`] = bid;
});
}
if (eventType === CONSTANTS.EVENTS.BID_TIMEOUT && utils.isArray(args)) {
const eventsStorage = yieldoneAnalytics.eventsStorage;
const reqBidders = {};
args.forEach((bid) => {
const reqBidId = `${bid.bidId}_${bid.auctionId}`;
const reqBidderId = `${bid.bidder}_${bid.auctionId}`;
if (!eventsStorage[bid.auctionId]) eventsStorage[bid.auctionId] = [];
if (requestedBidders[reqBidderId] && requestedBids[reqBidId]) {
if (!reqBidders[bid.bidder]) {
reqBidders[bid.bidder] = requestedBidders[reqBidderId];
reqBidders[bid.bidder].pubId = pubId;
eventsStorage[bid.auctionId].push({eventType, params: reqBidders[bid.bidder]});
delete requestedBidders[reqBidderId];
}
reqBidders[bid.bidder].bids.push(requestedBids[reqBidId]);
delete requestedBids[reqBidId];
}
});
} else {
args.pubId = pubId;
currentAuctionId = args.auctionId || currentAuctionId;
if (currentAuctionId) {
const eventsStorage = yieldoneAnalytics.eventsStorage;
if (!eventsStorage[currentAuctionId]) eventsStorage[currentAuctionId] = [];
const referrer = args.refererInfo && args.refererInfo.referer;
if (referrer && referrers[currentAuctionId] !== referrer) {
referrers[currentAuctionId] = referrer;
}
eventsStorage[currentAuctionId].push({
eventType,
params: args
});
}
}
if (
eventType === CONSTANTS.EVENTS.AUCTION_END || eventType === CONSTANTS.EVENTS.BID_WON
) {
args.adServerTargeting = targeting.getAllTargeting(
auctionManager.getAdUnitCodes(),
auctionManager.getBidsReceived()
);
if (yieldoneAnalytics.eventsStorage[args.auctionId]) {
yieldoneAnalytics.eventsStorage[args.auctionId].forEach((it) => {
it.page = {url: referrers[currentAuctionId]};
});
}
yieldoneAnalytics.sendStat(yieldoneAnalytics.eventsStorage[args.auctionId], args.auctionId);
}
},
sendStat(events, auctionId) {
if (!events) return;
delete yieldoneAnalytics.eventsStorage[auctionId];
ajax(
url,
{
success: function() {},
error: function() {}
},
JSON.stringify(events),
{
method: 'POST'
}
);
}
});

yieldoneAnalytics.eventsStorage = {};

// save the base class function
yieldoneAnalytics.originEnableAnalytics = yieldoneAnalytics.enableAnalytics;

// override enableAnalytics so we can get access to the config passed in from the page
yieldoneAnalytics.enableAnalytics = function (config) {
const options = config && config.options;
if (options) {
if (typeof options.url === 'string') {
url = options.url;
}
if (options.pubId) {
pubId = options.pubId.toString();
}
}
yieldoneAnalytics.originEnableAnalytics(config); // call the base class function
};

adapterManager.registerAnalyticsAdapter({
adapter: yieldoneAnalytics,
code: ANALYTICS_CODE
});

export default yieldoneAnalytics;
21 changes: 21 additions & 0 deletions modules/yieldoneAnalyticsAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Overview
Module Name: Platform One Analytics

Module Type: Analytics Adapter

Maintainer: y1s@platform-one.co.jp

# Description

Analytics adapter for Platform One. Please contact y1s@platform-one.co.jp for any additional information. Official website link to the vendor: www.platform-one.co.jp/.

# Test Parameters

```
{
provider: 'yieldone',
options : {
pubId : 'TestAnalyticsPublisher', //id provided by Platform One publisher team
}
}
```
Loading