@@ -39,14 +39,16 @@ const sanitiseLabel = (label: string): string => {
39
39
return label . replace ( / [ ^ a - z 0 - 9 ] + / gi, '-' )
40
40
}
41
41
42
+ export const defaultPostHogLabelProp = 'ph-label'
43
+
42
44
export const autocaptureFromTouchEvent = ( e : any , posthog : PostHog , options : PostHogAutocaptureOptions = { } ) : void => {
43
45
const {
44
46
noCaptureProp = 'ph-no-capture' ,
45
- customLabelProp = 'ph-label' ,
47
+ customLabelProp = defaultPostHogLabelProp ,
46
48
maxElementsCaptured = 20 ,
47
49
ignoreLabels = [ ] ,
48
- propsToCapture = [ 'style' , 'testID' , 'accessibilityLabel' , 'ph-label' , 'children' ] ,
49
50
} = options
51
+ const propsToCapture = [ 'style' , 'testID' , 'accessibilityLabel' , customLabelProp , 'children' ]
50
52
51
53
if ( ! e . _targetInst ) {
52
54
return
@@ -105,16 +107,16 @@ export const autocaptureFromTouchEvent = (e: any, posthog: PostHog, options: Pos
105
107
}
106
108
107
109
if ( elements . length ) {
108
- // The element that was tapped, may be a child (or grandchild of an element with a ph-label)
109
- // In this case, the current labels applied obscure the ph-label
110
- // To correct this, loop over the elements in reverse, and promote the ph-label
110
+ // The element that was tapped, may be a child (or grandchild of an element with a customLabelProp (default: ph-label) )
111
+ // In this case, the current labels applied obscure the customLabelProp (default: ph-label)
112
+ // To correct this, loop over the elements in reverse, and promote the customLabelProp (default: ph-label)
111
113
const elAttrLabelKey = `attr__${ customLabelProp } `
112
114
let lastLabel : string | undefined = undefined
113
115
114
116
for ( let i = elements . length - 1 ; i >= 0 ; i -- ) {
115
117
const element = elements [ i ]
116
118
if ( element [ elAttrLabelKey ] ) {
117
- // this element had a ph-label set, promote it to the lastLabel
119
+ // this element had a customLabelProp (default: ph-label) set, promote it to the lastLabel
118
120
lastLabel = element [ elAttrLabelKey ]
119
121
}
120
122
0 commit comments