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

IntentIQ Analytics Adapter: browser blacklist #12119

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
14 changes: 13 additions & 1 deletion modules/intentIqAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { config } from '../src/config.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_ANALYTICS } from '../src/activities/modules.js';

// Since IntentIQ analytics module work based on ID module configurations, there is shared code
// eslint-disable-next-line prebid/validate-imports
import { detectBrowser } from './intentIqIdSystem.js';
eyvazahmadzada marked this conversation as resolved.
Show resolved Hide resolved

const MODULE_NAME = 'iiqAnalytics'
const analyticsType = 'endpoint';
const defaultUrl = 'https://reports.intentiq.com/report';
Expand Down Expand Up @@ -112,6 +116,8 @@ function initLsValues() {
iiqAnalyticsAnalyticsAdapter.initOptions.partner = iiqArr[0].params.partner;
iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup = iiqAnalyticsAnalyticsAdapter.initOptions.fpid.group;
}

iiqAnalyticsAnalyticsAdapter.initOptions.browserBlackList = typeof iiqArr[0].params.browserBlackList === 'string' ? iiqArr[0].params.browserBlackList.toLowerCase() : '';
}
}

Expand All @@ -133,6 +139,13 @@ function initReadLsIds() {

function bidWon(args) {
if (!iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized) { initLsValues(); }

const currentBrowserLowerCase = detectBrowser();
if (iiqAnalyticsAnalyticsAdapter.initOptions.browserBlackList?.includes(currentBrowserLowerCase)) {
logError('IIQ ANALYTICS -> Browser is in blacklist!');
return;
}

if (iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized && !iiqAnalyticsAnalyticsAdapter.initOptions.lsIdsInitialized) { initReadLsIds(); }
if (!iiqAnalyticsAnalyticsAdapter.initOptions.manualReport) {
ajax(constructFullUrl(preparePayload(args, true)), undefined, null, { method: 'GET' });
Expand Down Expand Up @@ -225,7 +238,6 @@ iiqAnalyticsAnalyticsAdapter.originEnableAnalytics = iiqAnalyticsAnalyticsAdapte
iiqAnalyticsAnalyticsAdapter.enableAnalytics = function (myConfig) {
iiqAnalyticsAnalyticsAdapter.originEnableAnalytics(myConfig); // call the base class function
};

adapterManager.registerAnalyticsAdapter({
adapter: iiqAnalyticsAnalyticsAdapter,
code: MODULE_NAME
Expand Down
37 changes: 37 additions & 0 deletions test/spec/modules/intentIqAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ let wonRequest = {

describe('IntentIQ tests all', function () {
let logErrorStub;
let userAgentStub;

beforeEach(function () {
logErrorStub = sinon.stub(utils, 'logError');
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('IntentIQ tests all', function () {

afterEach(function () {
logErrorStub.restore();
if (userAgentStub) userAgentStub.restore();
config.getConfig.restore();
events.getEvents.restore();
iiqAnalyticsAnalyticsAdapter.disableAnalytics();
Expand Down Expand Up @@ -169,4 +171,39 @@ describe('IntentIQ tests all', function () {
expect(iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup).to.equal('B');
expect(iiqAnalyticsAnalyticsAdapter.initOptions.fpid).to.be.not.null;
});

it('should not send request if the browser is in blacklist (chrome)', function () {
const USERID_CONFIG_BROWSER = [...USERID_CONFIG];
USERID_CONFIG_BROWSER[0].params.browserBlackList = 'ChrOmE';
config.getConfig.restore();
sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG_BROWSER);

localStorage.setItem(FIRST_PARTY_KEY, defaultData);
events.emit(EVENTS.BID_WON, wonRequest);

expect(server.requests.length).to.equal(0);
expect(logErrorStub.calledOnce).to.be.true;
expect(logErrorStub.firstCall.args[0]).to.contain('IIQ ANALYTICS -> Browser is in blacklist!');
});

it('should send request if the browser is not in blacklist (safari)', function () {
const USERID_CONFIG_BROWSER = [...USERID_CONFIG];
USERID_CONFIG_BROWSER[0].params.browserBlackList = 'chrome,firefox';
config.getConfig.restore();
sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG_BROWSER);

localStorage.setItem(FIRST_PARTY_KEY, defaultData);
// Stub userAgent to simulate Safari
userAgentStub = sinon.stub(navigator, 'userAgent').value('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15');

events.emit(EVENTS.BID_WON, wonRequest);

expect(server.requests.length).to.be.above(0);
const request = server.requests[0];
expect(request.url).to.contain('https://reports.intentiq.com/report?pid=' + partner + '&mct=1');
expect(request.url).to.contain('&jsver=0.1&vrref=http://localhost:9876/');
expect(request.url).to.contain('&payload=');
expect(request.url).to.contain('iiqid=f961ffb1-a0e1-4696-a9d2-a21d815bd344');
expect(logErrorStub.called).to.be.false;
});
});