|
196 | 196 | statusCode: "cly_hc_status_code",
|
197 | 197 | errorMessage: "cly_hc_error_message"
|
198 | 198 | });
|
199 |
| - var SDK_VERSION = "23.12.3"; |
| 199 | + var SDK_VERSION = "23.12.4"; |
200 | 200 | var SDK_NAME = "javascript_native_web";
|
201 | 201 |
|
202 | 202 | // Using this on document.referrer would return an array with 15 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
|
|
519 | 519 | return uaOverride;
|
520 | 520 | }
|
521 | 521 | var ua_raw = navigator.userAgent;
|
522 |
| - // check if userAgentData is supported and userAgent is not available, use it |
| 522 | + // check if userAgentData is supported and userAgent is not available, then use it |
523 | 523 | if (!ua_raw) {
|
524 |
| - if (navigator.userAgentData) { |
525 |
| - // turn brands array into string |
526 |
| - ua_raw = navigator.userAgentData.brands.map(function (e) { |
527 |
| - return e.brand + ":" + e.version; |
528 |
| - }).join(); |
529 |
| - // add mobile info |
530 |
| - ua_raw += navigator.userAgentData.mobile ? " mobi " : " "; |
531 |
| - // add platform info |
532 |
| - ua_raw += navigator.userAgentData.platform; |
533 |
| - } |
| 524 | + ua_raw = currentUserAgentDataString(); |
534 | 525 | }
|
535 | 526 | // RAW USER AGENT STRING
|
536 | 527 | return ua_raw;
|
537 | 528 | }
|
538 | 529 |
|
| 530 | + /** |
| 531 | + * Forms user agent string from userAgentData by concatenating brand, version, mobile and platform |
| 532 | + * @memberof Countly._internals |
| 533 | + * @param {string} uaOverride - a string value to pass instead of ua value |
| 534 | + * @returns {string} currentUserAgentString - user agent string from userAgentData |
| 535 | + */ |
| 536 | + function currentUserAgentDataString(uaOverride) { |
| 537 | + if (uaOverride) { |
| 538 | + return uaOverride; |
| 539 | + } |
| 540 | + var ua = ""; |
| 541 | + if (navigator.userAgentData) { |
| 542 | + // turn brands array into string |
| 543 | + ua = navigator.userAgentData.brands.map(function (e) { |
| 544 | + return e.brand + ":" + e.version; |
| 545 | + }).join(); |
| 546 | + // add mobile info |
| 547 | + ua += navigator.userAgentData.mobile ? " mobi " : " "; |
| 548 | + // add platform info |
| 549 | + ua += navigator.userAgentData.platform; |
| 550 | + } |
| 551 | + return ua; |
| 552 | + } |
| 553 | + |
539 | 554 | /**
|
540 | 555 | * Returns device type information according to user agent string
|
541 | 556 | * @memberof Countly._internals
|
|
547 | 562 | // TODO: refactor here
|
548 | 563 | if (uaOverride) {
|
549 | 564 | userAgent = uaOverride;
|
550 |
| - } else if (navigator.userAgentData.mobile) { |
| 565 | + } else if (navigator.userAgentData && navigator.userAgentData.mobile) { |
551 | 566 | return "phone";
|
552 | 567 | } else {
|
553 | 568 | userAgent = currentUserAgentString();
|
|
581 | 596 | */
|
582 | 597 | function userAgentSearchBotDetection(uaOverride) {
|
583 | 598 | // search bot regexp
|
584 |
| - var searchBotRE = /(CountlySiteBot|nuhk|Googlebot|GoogleSecurityScanner|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver|bingbot|Google Web Preview|Mediapartners-Google|AdsBot-Google|Baiduspider|Ezooms|YahooSeeker|AltaVista|AVSearch|Mercator|Scooter|InfoSeek|Ultraseek|Lycos|Wget|YandexBot|Yandex|YaDirectFetcher|SiteBot|Exabot|AhrefsBot|MJ12bot|TurnitinBot|magpie-crawler|Nutch Crawler|CMS Crawler|rogerbot|Domnutch|ssearch_bot|XoviBot|netseer|digincore|fr-crawler|wesee|AliasIO|contxbot|PingdomBot|BingPreview|HeadlessChrome|Chrome-Lighthouse)/; |
585 |
| - // true if the user agent string contains a search bot string pattern |
586 |
| - return searchBotRE.test(uaOverride || currentUserAgentString()); |
| 599 | + var searchBotRE = /(CountlySiteBot|nuhk|Googlebot|GoogleSecurityScanner|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver|bingbot|Google Web Preview|Mediapartners-Google|AdsBot-Google|Baiduspider|Ezooms|YahooSeeker|AltaVista|AVSearch|Mercator|Scooter|InfoSeek|Ultraseek|Lycos|Wget|YandexBot|Yandex|YaDirectFetcher|SiteBot|Exabot|AhrefsBot|MJ12bot|TurnitinBot|magpie-crawler|Nutch Crawler|CMS Crawler|rogerbot|Domnutch|ssearch_bot|XoviBot|netseer|digincore|fr-crawler|wesee|AliasIO|contxbot|PingdomBot|BingPreview|HeadlessChrome|Lighthouse)/; |
| 600 | + |
| 601 | + // check override first |
| 602 | + if (uaOverride) { |
| 603 | + return searchBotRE.test(uaOverride); |
| 604 | + } |
| 605 | + |
| 606 | + // check both userAgent and userAgentData, as one of them might be containing the information we are looking for |
| 607 | + var ua_bot = searchBotRE.test(currentUserAgentString()); |
| 608 | + var uaData_bot = searchBotRE.test(currentUserAgentDataString()); |
| 609 | + return ua_bot || uaData_bot; |
587 | 610 | }
|
588 | 611 |
|
589 | 612 | /**
|
|
5161 | 5184 | processScrollView: processScrollView,
|
5162 | 5185 | processScroll: processScroll,
|
5163 | 5186 | currentUserAgentString: currentUserAgentString,
|
| 5187 | + currentUserAgentDataString: currentUserAgentDataString, |
5164 | 5188 | userAgentDeviceDetection: userAgentDeviceDetection,
|
5165 | 5189 | userAgentSearchBotDetection: userAgentSearchBotDetection,
|
5166 | 5190 | getRequestQueue: getRequestQueue,
|
|
0 commit comments