From af8901340d7dac0fe26a92e0550433ecb64ad0b5 Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Thu, 9 Jul 2020 13:23:58 +0200 Subject: [PATCH 1/7] ATS-analytics - fix check for safari browser --- modules/atsAnalyticsAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index 7bf2ca75c17..53146444e5f 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -67,7 +67,7 @@ export function browserIsChrome() { } export function browserIsSafari() { - if (navigator.vendor.indexOf('Apple')) { + if (navigator.vendor.indexOf('Apple') !== -1) { return 'Safari' } else { return false; From 0bbb39c0bf42bb84781fc9d62a2f327748ee1cc9 Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Fri, 10 Jul 2020 12:35:35 +0200 Subject: [PATCH 2/7] ATS-analytics - add unit tests for browser checks --- test/spec/modules/atsAnalyticsAdapter_spec.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index 3dd6f261c11..d448085ea7d 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -146,5 +146,44 @@ 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 () { + let browser = browserIsSafari(); + expect(browser).to.equal(false); + }) + it('check browser is safari', function () { + Object.defineProperty(window.navigator, 'vendor', { + value: 'Apple Computer, Inc.', + writable: true + }); + let browser = browserIsSafari(); + expect(browser).to.equal('Safari'); + }) + it('check browser is not chrome', function () { + 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 + }); + document.documentMode = undefined; + let browser = browserIsEdge(); + expect(browser).to.equal('Edge'); + }) + it('check browser is not edge', function () { + document.documentMode = {}; + let browser = browserIsEdge(); + expect(browser).to.equal(false); + }) }) }) From dfd145eff43a5d01e9e959d782480a782ca4ebb0 Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Fri, 10 Jul 2020 13:08:50 +0200 Subject: [PATCH 3/7] ATS-analytics - fix unit tests for browser checks --- test/spec/modules/atsAnalyticsAdapter_spec.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index d448085ea7d..e9d10539318 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -147,6 +147,10 @@ describe('ats analytics adapter', function () { expect(atsAnalyticsAdapter.context.pid).to.equal(initOptions.pid); }) it('check browser is not safari', function () { + Object.defineProperty(window.navigator, 'vendor', { + value: 'Google Inc.', + writable: true + }); let browser = browserIsSafari(); expect(browser).to.equal(false); }) @@ -159,6 +163,11 @@ describe('ats analytics adapter', function () { 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); }) @@ -176,12 +185,18 @@ describe('ats analytics adapter', function () { value: {}, writable: true }); - document.documentMode = undefined; + Object.defineProperty(document, 'documentMode', { + value: undefined, + writable: true + }); let browser = browserIsEdge(); expect(browser).to.equal('Edge'); }) it('check browser is not edge', function () { - document.documentMode = {}; + Object.defineProperty(document, 'documentMode', { + value: {}, + writable: true + }); let browser = browserIsEdge(); expect(browser).to.equal(false); }) From 3c927f4446b450559585378aa649aff868974706 Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Fri, 10 Jul 2020 15:17:03 +0200 Subject: [PATCH 4/7] ATS-analytics - fix unit tests for browser safari checks --- modules/atsAnalyticsAdapter.js | 2 +- test/spec/modules/atsAnalyticsAdapter_spec.js | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index 53146444e5f..1d0a1ca4840 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -67,7 +67,7 @@ export function browserIsChrome() { } export function browserIsSafari() { - if (navigator.vendor.indexOf('Apple') !== -1) { + if (window.safari !== undefined) { return 'Safari' } else { return false; diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index e9d10539318..f0bf64a18b8 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -147,18 +147,12 @@ describe('ats analytics adapter', function () { expect(atsAnalyticsAdapter.context.pid).to.equal(initOptions.pid); }) it('check browser is not safari', function () { - Object.defineProperty(window.navigator, 'vendor', { - value: 'Google Inc.', - writable: true - }); + window.safari = undefined; let browser = browserIsSafari(); expect(browser).to.equal(false); }) it('check browser is safari', function () { - Object.defineProperty(window.navigator, 'vendor', { - value: 'Apple Computer, Inc.', - writable: true - }); + window.safari = {}; let browser = browserIsSafari(); expect(browser).to.equal('Safari'); }) From 9d3b306d21507bdb2af3a979f2033999a70574ab Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Mon, 13 Jul 2020 10:46:51 +0200 Subject: [PATCH 5/7] ATS-analytics - change name for browser do not found --- modules/atsAnalyticsAdapter.js | 8 ++++---- test/spec/modules/atsAnalyticsAdapter_spec.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index 1d0a1ca4840..d5817ab5732 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -42,7 +42,7 @@ export function browserIsFirefox() { if (typeof InstallTrigger !== 'undefined') { return 'Firefox'; } else { - return false; + return 'Unknown'; } } @@ -54,7 +54,7 @@ export function browserIsEdge() { if (!browserIsIE() && !!window.StyleMedia) { return 'Edge'; } else { - return false; + return 'Unknown'; } } @@ -62,7 +62,7 @@ export function browserIsChrome() { if ((!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime)) || (/Android/i.test(navigator.userAgent) && !!window.chrome)) { return 'Chrome'; } else { - return false; + return 'Unknown'; } } @@ -70,7 +70,7 @@ export function browserIsSafari() { if (window.safari !== undefined) { return 'Safari' } else { - return false; + return 'Unknown'; } } diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index f0bf64a18b8..2a2dec4fcc1 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -149,7 +149,7 @@ describe('ats analytics adapter', function () { it('check browser is not safari', function () { window.safari = undefined; let browser = browserIsSafari(); - expect(browser).to.equal(false); + expect(browser).to.equal('Unknown'); }) it('check browser is safari', function () { window.safari = {}; @@ -163,7 +163,7 @@ describe('ats analytics adapter', function () { runtime: undefined }; let browser = browserIsChrome(); - expect(browser).to.equal(false); + expect(browser).to.equal('Unknown'); }) it('check browser is chrome', function () { window.chrome = { @@ -192,7 +192,7 @@ describe('ats analytics adapter', function () { writable: true }); let browser = browserIsEdge(); - expect(browser).to.equal(false); + expect(browser).to.equal('Unknown'); }) }) }) From 3b47c437987ef0ab0ad6f55a12f29abe263a678d Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Mon, 13 Jul 2020 11:34:10 +0200 Subject: [PATCH 6/7] ATS-analytics - add new logic for determine user browser --- modules/atsAnalyticsAdapter.js | 28 +++++++++++++++---- test/spec/modules/atsAnalyticsAdapter_spec.js | 10 +++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index d5817ab5732..ad488aa50d9 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -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, @@ -38,11 +38,29 @@ 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'; } else { - return 'Unknown'; + return false; } } @@ -54,7 +72,7 @@ export function browserIsEdge() { if (!browserIsIE() && !!window.StyleMedia) { return 'Edge'; } else { - return 'Unknown'; + return false; } } @@ -62,7 +80,7 @@ export function browserIsChrome() { if ((!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime)) || (/Android/i.test(navigator.userAgent) && !!window.chrome)) { return 'Chrome'; } else { - return 'Unknown'; + return false; } } @@ -70,7 +88,7 @@ export function browserIsSafari() { if (window.safari !== undefined) { return 'Safari' } else { - return 'Unknown'; + return false; } } diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index 2a2dec4fcc1..3ca5ee57e6c 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -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} from '../../../modules/atsAnalyticsAdapter.js'; let events = require('src/events'); let constants = require('src/constants.json'); @@ -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, @@ -149,7 +149,7 @@ describe('ats analytics adapter', function () { it('check browser is not safari', function () { window.safari = undefined; let browser = browserIsSafari(); - expect(browser).to.equal('Unknown'); + expect(browser).to.equal(false); }) it('check browser is safari', function () { window.safari = {}; @@ -163,7 +163,7 @@ describe('ats analytics adapter', function () { runtime: undefined }; let browser = browserIsChrome(); - expect(browser).to.equal('Unknown'); + expect(browser).to.equal(false); }) it('check browser is chrome', function () { window.chrome = { @@ -192,7 +192,7 @@ describe('ats analytics adapter', function () { writable: true }); let browser = browserIsEdge(); - expect(browser).to.equal('Unknown'); + expect(browser).to.equal(false); }) }) }) From f6f834ab2c5f7cb5145b02b83b60609df923178c Mon Sep 17 00:00:00 2001 From: "ma.matic" Date: Wed, 15 Jul 2020 10:30:08 +0200 Subject: [PATCH 7/7] ATS-analytics - add test for checking firefox browser --- test/spec/modules/atsAnalyticsAdapter_spec.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index 3ca5ee57e6c..849ccf88c51 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -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 {checkUserBrowser, browserIsChrome, browserIsEdge, 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'); @@ -194,5 +194,15 @@ describe('ats analytics adapter', function () { 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); + }) }) })