How to add telemetry to buttons and inputs in the Generic UI for external components
Learn how to send information about clicks and inputs in the Generic UI in the external components.
Last updated
Learn how to send information about clicks and inputs in the Generic UI in the external components.
Last updated
<button sendButtonTelemetry>
Let's begin
</button><button sendButtonTelemetry telemetry-value="Let's Start">
Let's begin
</button>import { Directive, ElementRef, HostListener } from '@angular/core';
import { MonitoringService } from 'src/app/services/monitoring/monitoring.service';
@Directive({
selector: '[sendButtonTelemetry]'
})
export class SendButtonTelemetryDirective {
constructor(private elementRef: ElementRef, private telemetryservice: MonitoringService) {}
@HostListener('click') onClick() {
let telemetryValue = this.elementRef.nativeElement.getAttribute("telemetry-value");
let buttonValue = this.elementRef.nativeElement.innerText;
this.sendTelemetry(`Button: ${telemetryValue || buttonValue}`)
}
sendTelemetry(value) {
this.telemetryservice.logEvent(value);
}
}
<input sendInputTelemetry telemetry-value="Full Report Email" formControlName="userEmail" placeholder="Enter your email"/>import { Directive, ElementRef, HostListener } from '@angular/core';
import { MonitoringService } from 'src/app/services/monitoring/monitoring.service';
@Directive({
selector: '[sendInputTelemetry]'
})
export class SendInputTelemetryDirective {
constructor(private elementRef: ElementRef, private telemetryService: MonitoringService) {}
@HostListener('change') onChange() {
this.sendTelemetry();
}
sendTelemetry() {
let telemetryValue = this.elementRef.nativeElement.getAttribute("telemetry-value");
let inputValue = this.elementRef.nativeElement.value;
this.telemetryService.logEvent(`Input: ${telemetryValue}`, [{value: inputValue}]);
}
}