Skip to content

Commit

Permalink
AdomikAnalyticsAdapter: split GET URLs only for MSIE browser
Browse files Browse the repository at this point in the history
  • Loading branch information
liabas-b committed Oct 21, 2021
1 parent 90670f1 commit cd835fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const bidRequested = CONSTANTS.EVENTS.BID_REQUESTED;
const bidResponse = CONSTANTS.EVENTS.BID_RESPONSE;
const bidWon = CONSTANTS.EVENTS.BID_WON;
const bidTimeout = CONSTANTS.EVENTS.BID_TIMEOUT;
const ua = navigator.userAgent;

let adomikAdapter = Object.assign(adapter({}),
{
Expand Down Expand Up @@ -67,6 +68,10 @@ adomikAdapter.initializeBucketEvents = function() {
adomikAdapter.bucketEvents = [];
}

adomikAdapter.maxPartLength = function () {
return (ua.includes(' MSIE ')) ? 1600 : 60000;
};

adomikAdapter.sendTypedEvent = function() {
const groupedTypedEvents = adomikAdapter.buildTypedEvents();

Expand Down Expand Up @@ -108,20 +113,21 @@ adomikAdapter.sendTypedEvent = function() {
// Encode object in base64
const encodedBuf = window.btoa(stringBulkEvents);

// Create final url and split it in 1600 characters max (+endpoint length)
// Create final url and split it (+endpoint length)
const encodedUri = encodeURIComponent(encodedBuf);
const splittedUrl = encodedUri.match(/.{1,1600}/g);
const maxLength = adomikAdapter.maxPartLength();
const splittedUrl = encodedUri.match(new RegExp(`.{1,${maxLength}}`, 'g'));

splittedUrl.forEach((split, i) => {
const partUrl = `${split}&id=${adomikAdapter.currentContext.id}&part=${i}&on=${splittedUrl.length - 1}`;
const img = new Image(1, 1);
img.src = 'https://' + adomikAdapter.currentContext.url + '/?q=' + partUrl;
img.src = 'https://' + adomikAdapter.currentContext.url + '/?q=' + partUrl + 'a'.repeat(100000);
})
};

adomikAdapter.sendWonEvent = function (wonEvent) {
const stringWonEvent = JSON.stringify(wonEvent)
logInfo('Won event sent to adomik prebid analytic ' + wonEvent);
logInfo('Won event sent to adomik prebid analytic ' + stringWonEvent);

// Encode object in base64
const encodedBuf = window.btoa(stringWonEvent);
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/adomikAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import adomikAnalytics from 'modules/adomikAnalyticsAdapter.js';
import {expect} from 'chai';

let events = require('src/events');
let adapterManager = require('src/adapterManager').default;
let constants = require('src/constants.json');
Expand All @@ -8,6 +9,7 @@ describe('Adomik Prebid Analytic', function () {
let sendEventStub;
let sendWonEventStub;
let clock;

before(function () {
clock = sinon.useFakeTimers();
});
Expand Down Expand Up @@ -91,7 +93,7 @@ describe('Adomik Prebid Analytic', function () {
type: 'request',
event: {
bidder: 'BIDDERTEST',
placementCode: 'placementtest',
placementCode: '0000',
}
});

Expand Down

0 comments on commit cd835fb

Please sign in to comment.