From bca1392b41143b9cd6113684fcbe5338a69b5e66 Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Fernadez Date: Tue, 24 Sep 2024 17:32:15 -0600 Subject: [PATCH] 24-sep-bach-fixes --- .../summary-simple-panel.component.ts | 2 +- .../trusted-summary.component.html | 12 +- .../trusted-summary.component.ts | 25 +++-- .../observability-events.service.ts | 106 ++++++++++++++++++ .../pages/my-orcid/my-orcid.component.ts | 3 + 5 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 src/app/core/observability-events/observability-events.service.ts diff --git a/src/app/cdk/trusted-summary/component/summary-simple-panel/summary-simple-panel.component.ts b/src/app/cdk/trusted-summary/component/summary-simple-panel/summary-simple-panel.component.ts index 5153a515c..4ebf186fe 100644 --- a/src/app/cdk/trusted-summary/component/summary-simple-panel/summary-simple-panel.component.ts +++ b/src/app/cdk/trusted-summary/component/summary-simple-panel/summary-simple-panel.component.ts @@ -46,7 +46,7 @@ export class SummarySimplePanelComponent implements OnInit { constructor(@Inject(WINDOW) private _window: Window) {} ngOnInit(): void { - this.acitivityCountOverflow = this.simpleActivities.length > 3 + this.acitivityCountOverflow = this.simpleActivities.length > 3 || this.count > 3 this.simpleActivities = this.simpleActivities.slice(0, 3) } goToUrl(url?: string, event?: KeyboardEvent) { diff --git a/src/app/cdk/trusted-summary/component/trusted-summary/trusted-summary.component.html b/src/app/cdk/trusted-summary/component/trusted-summary/trusted-summary.component.html index 3b6b8e377..bdacb8748 100644 --- a/src/app/cdk/trusted-summary/component/trusted-summary/trusted-summary.component.html +++ b/src/app/cdk/trusted-summary/component/trusted-summary/trusted-summary.component.html @@ -110,6 +110,7 @@

'panel-body-3-cols': !mobile }" > +
[activitySection]="'affiliations'" > - +

class="column" *ngIf=" trustedSummary.professionalActivities?.length || - externalIdentifiers?.length + externalIdentifiers?.length || + trustedSummary.educationQualifications?.length " > @@ -406,6 +410,8 @@

(click)="goToActivitySection('other-identifiers')" (keydown)="goToActivitySection('other-identifiers', $event)" [attr.aria-label]="ariaLabelIdentifiers" + (mouseenter)="externalIdentifiersHover = true" + (mouseleave)="externalIdentifiersHover = false" >

0 || this.funds.length > 0 || - this.peerReviews.length > 0) && + this.peerReviews.length > 0 || + this.researchResoruces.length) && (this.externalIdentifiers?.length > 0 || this.trustedSummary.professionalActivitiesCount > 0 || - this.trustedSummary.externalIdentifiers.length > 0 || - this.trustedSummary.externalIdentifiers.length > 0 || - this.researchResoruces.length > 0) + this.trustedSummary.educationQualifications?.length > 0) ) { this.threeColumns = true } else if ( this.works.length > 0 || this.funds.length > 0 || this.peerReviews.length > 0 || + this.researchResoruces.length > 0 || this.externalIdentifiers?.length > 0 || this.trustedSummary.professionalActivitiesCount > 0 || - this.researchResoruces.length > 0 + this.trustedSummary.educationQualifications?.length > 0 ) { this.twoColumns = true } else { this.oneColumn = true } + this._changeDetectorRef.markForCheck() this.ariaLabelAffiliations = this.getAriaLabelSection( this.labelViewAffiliations ) diff --git a/src/app/core/observability-events/observability-events.service.ts b/src/app/core/observability-events/observability-events.service.ts new file mode 100644 index 000000000..55f2a2c01 --- /dev/null +++ b/src/app/core/observability-events/observability-events.service.ts @@ -0,0 +1,106 @@ +import { Inject, Injectable } from '@angular/core' +import { WINDOW } from 'src/app/cdk/window' +import { environment } from 'src/environments/environment' + +export type journeyType = 'orcid_registration' | 'orcid_update_emails' +@Injectable({ + providedIn: 'root', +}) +export class CustomEventService { + // Store the start times of each journey + private journeys: { [key: string]: { startTime: number; attributes: any } } = + {} + + constructor(@Inject(WINDOW) private window: Window) {} + + /** + * Starts a new user journey. + * @param journeyType The type of the journey (e.g., 'orcid_registration', 'orcid_update_emails'). + * @param attributes Additional attributes to store with the journey + */ + startJourney(journeyType: journeyType, attributes: any = {}): void { + + + // Record the start time and initial attributes + this.journeys[journeyType] = { + startTime: Date.now(), + attributes, + } + + if (environment.debugger) { + console.debug( + `-> Journey "${journeyType}" started at ${this.journeys[journeyType].startTime}` + ) + } + } + + /** + * Records an event within the journey. + * @param journeyType The type of the journey (e.g., 'orcid_registration'). + * @param eventName The name of the event to track (e.g., 'page_loaded', 'form_submitted'). + * @param additionalAttributes Any additional attributes related to the event. + */ + recordEvent( + journeyType: string, + eventName: string, + additionalAttributes: any = {} + ): void { + if (!this.journeys[journeyType]) { + console.error(`Journey "${journeyType}" not started.`) + return + } + + // Calculate time since the start of the journey + const elapsedTime = Date.now() - this.journeys[journeyType].startTime + + // Combine the journey attributes with additional attributes + const eventAttributes = { + ...this.journeys[journeyType].attributes, + ...additionalAttributes, + eventName, + elapsedTime, + } + ;(this.window as any).newrelic.addPageAction(journeyType, eventAttributes) + + // Send the custom event to New Relic + + if (environment.debugger) { + console.debug( + `-> Event "${eventName}" recorded for journey "${journeyType}" with elapsed time ${elapsedTime}ms` + ) + } + } + + /** + * Finishes the user journey. + * @param journeyType The type of the journey (e.g., 'orcid_registration'). + * @param additionalAttributes Any final attributes or metadata to log at the end of the journey. + */ + finishJourney(journeyType: string, additionalAttributes: any = {}): void { + if (!this.journeys[journeyType]) { + console.error(`Journey "${journeyType}" not started.`) + return + } + + // Calculate time since the start of the journey + const elapsedTime = Date.now() - this.journeys[journeyType].startTime + + // Final event attributes + const finalAttributes = { + ...this.journeys[journeyType].attributes, + ...additionalAttributes, + eventName: 'journey_finished', + elapsedTime, + } + + // Send the final custom event to New Relic + ;(this.window as any).addPageAction(journeyType, finalAttributes) + + // Clean up the journey data + delete this.journeys[journeyType] + + console.log( + `Journey "${journeyType}" finished with elapsed time ${elapsedTime}ms` + ) + } +} diff --git a/src/app/record/pages/my-orcid/my-orcid.component.ts b/src/app/record/pages/my-orcid/my-orcid.component.ts index c1405aec5..45317dc24 100644 --- a/src/app/record/pages/my-orcid/my-orcid.component.ts +++ b/src/app/record/pages/my-orcid/my-orcid.component.ts @@ -185,6 +185,9 @@ export class MyOrcidComponent implements OnInit, OnDestroy { 'peer-reviews', 'funding', 'professional-activities', + 'research-resources', + 'emails-panel', + 'education-and-qualification' ].find((x) => x === this.fragment) ) { setTimeout(() => {