@@ -34,7 +34,6 @@ import { AttributeNames } from './enums/AttributeNames';
3434import { VERSION } from './version' ;
3535
3636const ZONE_CONTEXT_KEY = 'OT_ZONE_CONTEXT' ;
37- const EVENT_CLICK_NAME = 'event_click:' ;
3837const EVENT_NAVIGATION_NAME = 'Navigation:' ;
3938
4039/**
@@ -80,6 +79,12 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
8079 }
8180 }
8281
82+ /**
83+ * Controls whether or not to create a span, based on the event type.
84+ */
85+ protected _allowEventType ( eventType : string ) : boolean {
86+ return eventType === 'click' ;
87+ }
8388 /**
8489 * Creates a new span
8590 * @param element
@@ -95,9 +100,12 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
95100 if ( element . hasAttribute ( 'disabled' ) ) {
96101 return undefined ;
97102 }
103+ if ( ! this . _allowEventType ( eventName ) ) {
104+ return undefined ;
105+ }
98106 const xpath = getElementXPath ( element , true ) ;
99107 try {
100- const span = this . _tracer . startSpan ( ` ${ EVENT_CLICK_NAME } ${ xpath } ` , {
108+ const span = this . _tracer . startSpan ( eventName , {
101109 attributes : {
102110 [ AttributeNames . COMPONENT ] : this . component ,
103111 [ AttributeNames . EVENT_TYPE ] : eventName ,
@@ -147,17 +155,6 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
147155 return context ;
148156 }
149157
150- /**
151- * It gets the element that has been clicked when zone tries to run a new task
152- * @param task
153- */
154- private _getClickedElement ( task : AsyncTask ) : HTMLElement | undefined {
155- if ( task . eventName === 'click' ) {
156- return task . target ;
157- }
158- return undefined ;
159- }
160-
161158 /**
162159 * Increment number of tasks that are run within the same zone.
163160 * This is needed to be able to end span when no more tasks left
@@ -245,7 +242,7 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
245242 if ( once ) {
246243 plugin . removePatchedListener ( this , type , listener ) ;
247244 }
248- const span = plugin . _createSpan ( target , 'click' ) ;
245+ const span = plugin . _createSpan ( target , type ) ;
249246 if ( span ) {
250247 return plugin . _tracer . withSpan ( span , ( ) => {
251248 const result = listener . apply ( target , args ) ;
@@ -405,11 +402,11 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
405402 applyThis ?: any ,
406403 applyArgs ?: any
407404 ) : Zone {
408- const target : HTMLElement | undefined = plugin . _getClickedElement ( task ) ;
405+ const target : HTMLElement | undefined = task . target ;
409406 let span : api . Span | undefined ;
410407 const activeZone = this ;
411408 if ( target ) {
412- span = plugin . _createSpan ( target , 'click' ) ;
409+ span = plugin . _createSpan ( target , task . eventName ) ;
413410 if ( span ) {
414411 plugin . _incrementTask ( span ) ;
415412 return activeZone . run ( ( ) => {
@@ -568,6 +565,7 @@ export class UserInteractionPlugin extends BasePlugin<unknown> {
568565 shimmer . unwrap ( ZoneWithPrototype . prototype , 'cancelTask' ) ;
569566 } else {
570567 shimmer . unwrap ( HTMLElement . prototype , 'addEventListener' ) ;
568+ shimmer . unwrap ( HTMLElement . prototype , 'removeEventListener' ) ;
571569 }
572570 this . _unpatchHistoryApi ( ) ;
573571 }
0 commit comments