@@ -58,7 +58,13 @@ export function enableButtonClickTracking(
58
58
// Store the configuration for this tracker, if it doesn't already exist
59
59
// This allows us to enable click tracking for a tracker if it has been disabled
60
60
_listeners [ trackerId ] = ( event : MouseEvent ) => {
61
- eventHandler ( event , trackerId , filterFunctionFromFilter ( configuration . filter ) , configuration . context ) ;
61
+ eventHandler (
62
+ event ,
63
+ trackerId ,
64
+ filterFunctionFromFilter ( configuration . filter ) ,
65
+ configuration . defaultLabel ,
66
+ configuration . context
67
+ ) ;
62
68
} ;
63
69
64
70
const addClickListener = ( ) => {
@@ -96,12 +102,18 @@ export function disableButtonClickTracking(trackers: Array<string> = Object.keys
96
102
* @param filter - The filter function to use for button click tracking
97
103
* @param context - The dynamic context which will be evaluated for each button click event
98
104
*/
99
- function eventHandler ( event : MouseEvent , trackerId : string , filter : FilterFunction , context ?: DynamicContext ) {
105
+ function eventHandler (
106
+ event : MouseEvent ,
107
+ trackerId : string ,
108
+ filter : FilterFunction ,
109
+ defaultLabel ?: string | ( ( element : HTMLElement ) => string ) ,
110
+ context ?: DynamicContext
111
+ ) {
100
112
let elem = ( event . composed ? event . composedPath ( ) [ 0 ] : event . target ) as HTMLElement | null ;
101
113
while ( elem ) {
102
114
if ( elem instanceof HTMLButtonElement || ( elem instanceof HTMLInputElement && elem . type === 'button' ) ) {
103
115
if ( filter ( elem ) ) {
104
- const buttonClickEvent = createEventFromButton ( elem ) ;
116
+ const buttonClickEvent = createEventFromButton ( elem , defaultLabel ) ;
105
117
buttonClickEvent . context = resolveDynamicContext ( context , buttonClickEvent , elem ) ;
106
118
trackButtonClick ( buttonClickEvent , [ trackerId ] ) ;
107
119
}
0 commit comments