Skip to content
Merged
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
24 changes: 15 additions & 9 deletions modules/openxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function buildUtmLocalStorageKey(utmMarkKey) {
return localStoragePrefix.concat(utmMarkKey);
}

function checkPublisherPlatformId() {
function getPublisherPlatformId() {
if (initOptions.publisherPlatformId !== undefined) {
if (typeof initOptions.publisherPlatformId === 'string') {
if (initOptions.publisherPlatformId !== '') {
Expand All @@ -125,7 +125,7 @@ function checkPublisherPlatformId() {
}
}

function checkPublisherAccountId() {
function getPublisherAccountId() {
if (initOptions.publisherAccountId !== undefined) {
if (typeof initOptions.publisherAccountId === 'number') {
if (initOptions.publisherAccountId > -1) {
Expand All @@ -144,7 +144,7 @@ function checkPublisherAccountId() {
}
}

function checkTestCode() {
function getTestCode() {
if (initOptions.testCode !== undefined) {
if (typeof initOptions.testCode === 'string') {
return initOptions.testCode;
Expand All @@ -159,9 +159,9 @@ function checkTestCode() {
}

function checkInitOptions() {
let publisherPlatformId = checkPublisherPlatformId();
let publisherAccountId = checkPublisherAccountId();
let testCode = checkTestCode();
let publisherPlatformId = getPublisherPlatformId();
let publisherAccountId = getPublisherAccountId();
let testCode = getTestCode();
if (publisherPlatformId && publisherAccountId && testCode) {
return true;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ openxAdapter.originEnableAnalytics = openxAdapter.enableAnalytics;

openxAdapter.enableAnalytics = function(config) {
initOptions = config.options;
initOptions.testCode = checkTestCode();
initOptions.testCode = getTestCode();
initOptions.utmTagData = this.buildUtmTagData();
utils.logInfo('OpenX Analytics enabled with config', initOptions);
openxAdapter.originEnableAnalytics(config);
Expand Down Expand Up @@ -334,6 +334,7 @@ function buildPayload(
eventType,
publisherPlatformId,
publisherAccountId,
auctionId,
testCode,
sourceUrl
) {
Expand All @@ -342,12 +343,13 @@ function buildPayload(
eventType: eventType,
publisherPlatformId: publisherPlatformId,
publisherAccountId: publisherAccountId,
auctionId: auctionId,
testCode: testCode,
sourceUrl: sourceUrl
};
}

function apiCall(url, MAX_RETRIES, payload, auctionId) {
function apiCall(url, MAX_RETRIES, payload) {
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState !== 4) return;
Expand All @@ -371,6 +373,9 @@ function apiCall(url, MAX_RETRIES, payload, auctionId) {
if (payload.publisherAccountId) {
xhr.setRequestHeader('PublisherAccountId', payload.publisherAccountId);
}
if (payload.publisherAccountId) {
xhr.setRequestHeader('AuctionId', payload.auctionId);
}
xhr.setRequestHeader('Source-Url', payload.sourceUrl);
xhr.timeout = MAX_TIMEOUT;
xhr.send(payload.data);
Expand Down Expand Up @@ -469,10 +474,11 @@ function send(eventType, eventStack, auctionId) {
eventType,
publisherPlatformId,
publisherAccountId,
auctionId,
testCode,
sourceUrl
);
apiCall(urlGenerated, MAX_RETRIES, payload, auctionId);
apiCall(urlGenerated, MAX_RETRIES, payload);
} else {
utils.logError('OX: Invalid data format');
delete eventStack[auctionId];
Expand Down