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

ATS-analytics - fix check for safari browser #5474

Merged
merged 7 commits into from
Jul 16, 2020
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
22 changes: 20 additions & 2 deletions modules/atsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function bidRequestedHandler(args) {
bidder: bid.bidder,
bid_id: bid.bidId,
auction_id: args.auctionId,
user_browser: (browserIsFirefox() || browserIsEdge() || browserIsChrome() || browserIsSafari()),
user_browser: checkUserBrowser(),
user_platform: navigator.platform,
auction_start: new Date(args.auctionStart).toJSON(),
domain: window.location.hostname,
Expand All @@ -38,6 +38,24 @@ function bidResponseHandler(args) {
};
}

export function checkUserBrowser() {
let firefox = browserIsFirefox();
let chrome = browserIsChrome();
let edge = browserIsEdge();
let safari = browserIsSafari();
if (firefox) {
return firefox;
} if (chrome) {
return chrome;
} if (edge) {
return edge;
} if (safari) {
return safari;
} else {
return 'Unknown'
}
}

export function browserIsFirefox() {
if (typeof InstallTrigger !== 'undefined') {
return 'Firefox';
Expand Down Expand Up @@ -67,7 +85,7 @@ export function browserIsChrome() {
}

export function browserIsSafari() {
if (navigator.vendor.indexOf('Apple')) {
if (window.safari !== undefined) {
return 'Safari'
} else {
return false;
Expand Down
62 changes: 60 additions & 2 deletions test/spec/modules/atsAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import atsAnalyticsAdapter from '../../../modules/atsAnalyticsAdapter.js';
import { expect } from 'chai';
import adapterManager from 'src/adapterManager.js';
import {server} from '../../mocks/xhr.js';
import {browserIsChrome, browserIsEdge, browserIsFirefox, browserIsSafari} from '../../../modules/atsAnalyticsAdapter.js';
import {checkUserBrowser, browserIsChrome, browserIsEdge, browserIsSafari, browserIsFirefox} from '../../../modules/atsAnalyticsAdapter.js';
let events = require('src/events');
let constants = require('src/constants.json');

Expand Down Expand Up @@ -77,7 +77,7 @@ describe('ats analytics adapter', function () {
'bidder': 'appnexus',
'bid_id': '30c77d079cdf17',
'auction_id': 'a5b849e5-87d7-4205-8300-d063084fcfb7',
'user_browser': (browserIsFirefox() || browserIsEdge() || browserIsChrome() || browserIsSafari()),
'user_browser': checkUserBrowser(),
'user_platform': navigator.platform,
'auction_start': '2020-02-03T14:14:25.161Z',
'domain': window.location.hostname,
Expand Down Expand Up @@ -146,5 +146,63 @@ describe('ats analytics adapter', function () {
expect(atsAnalyticsAdapter.context.host).to.equal(initOptions.host);
expect(atsAnalyticsAdapter.context.pid).to.equal(initOptions.pid);
})
it('check browser is not safari', function () {
window.safari = undefined;
let browser = browserIsSafari();
expect(browser).to.equal(false);
})
it('check browser is safari', function () {
window.safari = {};
let browser = browserIsSafari();
expect(browser).to.equal('Safari');
})
it('check browser is not chrome', function () {
window.chrome = {
app: undefined,
webstore: undefined,
runtime: undefined
};
let browser = browserIsChrome();
expect(browser).to.equal(false);
})
it('check browser is chrome', function () {
window.chrome = {
app: {},
webstore: {},
runtime: {}
};
let browser = browserIsChrome();
expect(browser).to.equal('Chrome');
})
it('check browser is edge', function () {
Object.defineProperty(window, 'StyleMedia', {
value: {},
writable: true
});
Object.defineProperty(document, 'documentMode', {
value: undefined,
writable: true
});
let browser = browserIsEdge();
expect(browser).to.equal('Edge');
})
it('check browser is not edge', function () {
Object.defineProperty(document, 'documentMode', {
value: {},
writable: true
});
let browser = browserIsEdge();
expect(browser).to.equal(false);
})
it('check browser is firefox', function () {
global.InstallTrigger = {};
let browser = browserIsFirefox();
expect(browser).to.equal('Firefox');
})
it('check browser is not firefox', function () {
global.InstallTrigger = undefined;
let browser = browserIsFirefox();
expect(browser).to.equal(false);
})
})
})