Skip to content

Commit 6155bc5

Browse files
authored
DR | Wrap RUM init in window load (#2219)
* Wrap RUM init in window load * Update DataDog CDN url
1 parent 49424b8 commit 6155bc5

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed
+43-40
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
1+
<!-- src url from https://docs.datadoghq.com/real_user_monitoring/browser/setup/#cdn-sync -->
12
<script
23
nonce="**CSP_NONCE**"
34
type="text/javascript"
45
defer
5-
src="https://www.datadoghq-browser-agent.com/us1/v5/datadog-rum.js"
6+
src="https://www.datadoghq-browser-agent.com/datadog-rum-v5.js"
67
></script>
78
<script nonce="**CSP_NONCE**" type="text/javascript">
8-
// All of the page urls we want to monitor include www.va.gov (production only)
9-
if (window.DD_RUM && window.location?.hostname === 'www.va.gov') {
10-
/**
11-
* Unauthenticated Static pages may be crawled by bots, so we won't initialize
12-
* RUM sessions. The following code is from DataDog:
13-
* https://docs.datadoghq.com/real_user_monitoring/guide/identify-bots-in-the-ui
14-
*/
15-
// regex patterns to identify known bot instances (5/2024):
16-
const botPattern = '(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)';
17-
const regex = new RegExp(botPattern, 'i');
9+
window.addEventListener('load', () => {
10+
// All of the page urls we want to monitor include www.va.gov (production only)
11+
if (window.DD_RUM && window.location?.hostname === 'www.va.gov') {
12+
/**
13+
* Unauthenticated Static pages may be crawled by bots, so we won't initialize
14+
* RUM sessions. The following code is from DataDog:
15+
* https://docs.datadoghq.com/real_user_monitoring/guide/identify-bots-in-the-ui
16+
*/
17+
// regex patterns to identify known bot instances (5/2024):
18+
const botPattern = '(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)';
19+
const regex = new RegExp(botPattern, 'i');
1820

19-
// Don't initialize RUM if a bot is crawling the page
20-
const isBot = regex.test(navigator.userAgent);
21+
// Don't initialize RUM if a bot is crawling the page
22+
const isBot = regex.test(navigator.userAgent);
2123

22-
/**
23-
* Initialize DataDog Real User Monitoring (RUM) sessions
24-
* https://docs.datadoghq.com/real_user_monitoring/browser/#cdn-sync
25-
*/
26-
if (
27-
!isBot &&
28-
// is DataDog is already initialized?
29-
!window.DD_RUM?.getInitConfiguration()
30-
) {
31-
window.DD_RUM.init({
32-
site: 'ddog-gov.com',
33-
env: 'production',
34-
version: '1.0.0',
35-
service: 'benefits-decision-review-static-pages',
36-
clientToken: 'pub17c22ff5e9e7e51f7ac28b828741e21a',
37-
applicationId: '133801ec-0b13-4a6f-9689-bd937a1ddf27',
24+
/**
25+
* Initialize DataDog Real User Monitoring (RUM) sessions
26+
* https://docs.datadoghq.com/real_user_monitoring/browser/#cdn-sync
27+
*/
28+
if (
29+
!isBot &&
30+
// is DataDog is already initialized?
31+
!window.DD_RUM?.getInitConfiguration()
32+
) {
33+
window.DD_RUM.init({
34+
site: 'ddog-gov.com',
35+
env: 'production',
36+
version: '1.0.0',
37+
service: 'benefits-decision-review-static-pages',
38+
clientToken: 'pub17c22ff5e9e7e51f7ac28b828741e21a',
39+
applicationId: '133801ec-0b13-4a6f-9689-bd937a1ddf27',
3840

39-
sessionSampleRate: 10, // {% if decisionReviewRum %}
40-
sessionReplaySampleRate: 20,
41+
sessionSampleRate: 10, // {% if decisionReviewRum %}
42+
sessionReplaySampleRate: 20,
4143

42-
trackInteractions: true,
43-
trackUserInteractions: true,
44-
trackResources: true,
45-
trackLongTasks: true,
44+
trackInteractions: true,
45+
trackUserInteractions: true,
46+
trackResources: true,
47+
trackLongTasks: true,
4648

47-
// https://docs.datadoghq.com/real_user_monitoring/session_replay/browser/privacy_options/
48-
defaultPrivacyLevel: 'mask-user-input',
49-
});
50-
window.DD_RUM.startSessionReplayRecording();
49+
// https://docs.datadoghq.com/real_user_monitoring/session_replay/browser/privacy_options/
50+
defaultPrivacyLevel: 'mask-user-input',
51+
});
52+
window.DD_RUM.startSessionReplayRecording();
53+
}
5154
}
52-
}
55+
});
5356
</script>

0 commit comments

Comments
 (0)