From 5244e1ff9b8c786f472a9c783784b80a59c5ecd6 Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Fernadez Date: Tue, 3 Sep 2024 14:10:37 -0600 Subject: [PATCH 1/2] new relic --- scripts/new-relic.postbuild.ts | 65 +++++++++++++++++++ scripts/postbuild.ts | 2 + src/app/app.component.ts | 12 +++- .../cdk/platform-info/browserlist.regexp.ts | 3 +- src/app/core/new-relic/new-relic.service.ts | 18 +++++ .../environment.local-with-proxy.ts | 1 + src/environments/environment.local.ts | 1 + src/environments/environment.production.ts | 1 + src/environments/environment.qa.ts | 1 + src/environments/environment.sandbox.ts | 1 + src/index.html | 1 + 11 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 scripts/new-relic.postbuild.ts create mode 100644 src/app/core/new-relic/new-relic.service.ts diff --git a/scripts/new-relic.postbuild.ts b/scripts/new-relic.postbuild.ts new file mode 100644 index 0000000000..e350b3947f --- /dev/null +++ b/scripts/new-relic.postbuild.ts @@ -0,0 +1,65 @@ +export function newRelic(indexHtml: string, options) { + if ( + options.environmentVariables && + options.environmentVariables.NEW_RELIC_APP + ) { + return indexHtml.replace( + '', + ` ` + + ) + } else { + console.warn( + 'This build will not have google analytics since the UID is not defined on the environment variables' + ) + return indexHtml + } +} diff --git a/scripts/postbuild.ts b/scripts/postbuild.ts index c7ac6c734b..980b49bbe0 100644 --- a/scripts/postbuild.ts +++ b/scripts/postbuild.ts @@ -11,6 +11,7 @@ import { renameSync, readFileSync } from 'fs' import { zendeskPlugin } from './zend-desk.postbuild' import { createShareAssetsFolder } from './moveToShareFolder.postbuild' import { robotsMetadata } from './robots-metada.postbuild' +import { newRelic } from './new-relic.postbuild' const glob = require('glob') // Run updates on index.html files across languages glob @@ -20,6 +21,7 @@ glob let data = readFileSync(file, 'utf8') data = uniqueLength(data, options) data = buildInfo(data, options) + data = newRelic(data, options) data = zendeskPlugin(data, options) // Replace all the `*.js` references to match updated JS file names with the language code. data = addLanguageCodeToHashesOnToHTMLFiles(data, options) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 26c4975593..1136690134 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -16,6 +16,8 @@ import { GoogleTagManagerService } from './core/google-tag-manager/google-tag-ma import { TitleService } from './core/title-service/title.service' import { ZendeskService } from './core/zendesk/zendesk.service' import { ERROR_REPORT } from './errors' +import { TogglzService } from './core/togglz/togglz.service' +import { NewRelicService } from './core/new-relic/new-relic.service' @Component({ selector: 'app-root', @@ -49,7 +51,9 @@ export class AppComponent { private _userService: UserService, private _errorHandler: ErrorHandlerService, @Inject(WINDOW) private _window: Window, - _titleService: TitleService + _titleService: TitleService, + _togglzService: TogglzService, + _newRelicService: NewRelicService ) { _titleService.init() _platformInfo @@ -81,6 +85,12 @@ export class AppComponent { ) .subscribe() + _togglzService.getStateOf('NEW_RELIC_BROWSER_MONITORING').subscribe((value) => { + if (true) { + _newRelicService.init() + } + }) + _router.events.subscribe((event) => { if (event instanceof NavigationStart) { reportNavigationStart(event.url) diff --git a/src/app/cdk/platform-info/browserlist.regexp.ts b/src/app/cdk/platform-info/browserlist.regexp.ts index 545a90290e..bf8c4aa5cf 100644 --- a/src/app/cdk/platform-info/browserlist.regexp.ts +++ b/src/app/cdk/platform-info/browserlist.regexp.ts @@ -1,3 +1,2 @@ // tslint:disable-next-line: max-line-length -export const BROWSERLIST_REGEXP = - /((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/ +export const BROWSERLIST_REGEXP = /((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/ diff --git a/src/app/core/new-relic/new-relic.service.ts b/src/app/core/new-relic/new-relic.service.ts new file mode 100644 index 0000000000..260e35f324 --- /dev/null +++ b/src/app/core/new-relic/new-relic.service.ts @@ -0,0 +1,18 @@ +import { Inject, Injectable } from '@angular/core' +import { WINDOW } from 'src/app/cdk/window' + +@Injectable({ + providedIn: 'root', +}) +export class NewRelicService { + + constructor( @Inject(WINDOW) private window: Window, +) {} + + public init() { + if ((window as any).newrelic) { + (window as any).newrelic.addPageAction('init') + } + } + +} diff --git a/src/environments/environment.local-with-proxy.ts b/src/environments/environment.local-with-proxy.ts index 483483453b..f78e9f60bd 100644 --- a/src/environments/environment.local-with-proxy.ts +++ b/src/environments/environment.local-with-proxy.ts @@ -18,6 +18,7 @@ export const environment = { VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://homepage-qa.orcid.org', WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org', + NEW_RELIC_APP: '772335827', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.local.ts b/src/environments/environment.local.ts index 8553fdc68a..975d5c70fd 100644 --- a/src/environments/environment.local.ts +++ b/src/environments/environment.local.ts @@ -18,6 +18,7 @@ export const environment = { VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://homepage-qa.orcid.org', WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org', + NEW_RELIC_APP: '772335827', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 7a5a1b234e..3ed290aae8 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -17,6 +17,7 @@ export const environment = { VERBOSE_SNACKBAR_ERRORS_REPORTS: false, WORDPRESS_S3: 'https://homepage-prod.orcid.org', WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org', + NEW_RELIC_APP: '772335825', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.qa.ts b/src/environments/environment.qa.ts index 6ac196ace3..ee232719a1 100644 --- a/src/environments/environment.qa.ts +++ b/src/environments/environment.qa.ts @@ -18,6 +18,7 @@ export const environment = { VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://homepage-qa.orcid.org', WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org', + NEW_RELIC_APP: '772335827', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.sandbox.ts b/src/environments/environment.sandbox.ts index 3e472cc637..cea92e6dcc 100644 --- a/src/environments/environment.sandbox.ts +++ b/src/environments/environment.sandbox.ts @@ -18,6 +18,7 @@ export const environment = { VERBOSE_SNACKBAR_ERRORS_REPORTS: false, WORDPRESS_S3: 'https://homepage-prod.orcid.org', WORDPRESS_S3_FALLBACK: 'https://homepage-fallback.orcid.org', + NEW_RELIC_APP: '772335828', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/index.html b/src/index.html index 96bf64f5dc..75d6f26a56 100644 --- a/src/index.html +++ b/src/index.html @@ -9,6 +9,7 @@ + Date: Tue, 3 Sep 2024 14:13:52 -0600 Subject: [PATCH 2/2] new relic --- src/app/core/new-relic/new-relic.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/new-relic/new-relic.service.ts b/src/app/core/new-relic/new-relic.service.ts index 260e35f324..17b551b7de 100644 --- a/src/app/core/new-relic/new-relic.service.ts +++ b/src/app/core/new-relic/new-relic.service.ts @@ -10,8 +10,8 @@ export class NewRelicService { ) {} public init() { - if ((window as any).newrelic) { - (window as any).newrelic.addPageAction('init') + if ((window as any)?.newrelic?.start && typeof (window as any).newrelic.start === 'function' ) { + (window as any).newrelic.start() } }