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

ADS-3448 Add browser type to Hummingbird data #19

Merged
merged 4 commits into from
Apr 3, 2020
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
36 changes: 36 additions & 0 deletions modules/mavenAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let mavenAnalytics = Object.assign(adapter({hummingbirdUrl, analyticsType}), {
}
auctionObj = {
auctionId: id,
browserType: options.browserType,
connectionEffectiveType: connType,
contentItemId: options.contentItemId,
correlator: window.hummingbirdCorrelator,
Expand Down Expand Up @@ -199,12 +200,47 @@ mavenAnalytics.enableAnalytics = function (config) {
return;
}
options = config.options;
options.browserType = this.generateBrowserType();
mavenAnalytics.originEnableAnalytics(config); // call the base class function
initialized = true;
hummingbirdUrl = options.url;
verbose = !!options.verbose;
};

mavenAnalytics.generateBrowserType = function() {
// Browser sniffing -- this gets us all browser families with >1% of
// traffic, according to the 2019 Wikimedia report. This set of tests
// is largely based on
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
// and should be relatively resilient to changes in user-agent behavior.
//
// We can't use String.prototype.includes to allow support of IE.
let ua = navigator.userAgent;
if (ua.indexOf('Chrome/') >= 0) {
if (ua.indexOf('OPR/') >= 0) {
return 'opera';
} else if (ua.indexOf('Edg/') >= 0 || ua.indexOf('Edge') >= 0) {
return 'edge';
} else if (ua.indexOf('SamsungBrowser') >= 0) {
return 'samsung';
} else if (ua.indexOf('Chromium/') == -1) {
// Chromium could be Chromium, Brave, etc.
return 'chrome';
bradchoate marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (ua.indexOf('Safari/') >= 0) {
return 'safari';
} else if (ua.indexOf('Firefox/') >= 0) {
if (ua.indexOf('Seamonkey/') == -1) {
return 'firefox';
}
} else if (ua.indexOf('Trident/') >= 0 || ua.indexOf('MSIE') >= 0) {
return 'ie';
} else if (ua.indexOf('OPR/') >= 0 || ua.indexOf('Opera/') >= 0) {
return 'opera';
bradchoate marked this conversation as resolved.
Show resolved Hide resolved
}
return 'other';
}

adaptermanager.registerAnalyticsAdapter({
adapter: mavenAnalytics,
code: 'maven'
Expand Down