-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: capture customLabelProp if set #302
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,14 +39,16 @@ const sanitiseLabel = (label: string): string => { | |
return label.replace(/[^a-z0-9]+/gi, '-') | ||
} | ||
|
||
export const defaultPostHogLabelProp = 'ph-label' | ||
|
||
export const autocaptureFromTouchEvent = (e: any, posthog: PostHog, options: PostHogAutocaptureOptions = {}): void => { | ||
const { | ||
noCaptureProp = 'ph-no-capture', | ||
customLabelProp = 'ph-label', | ||
customLabelProp = defaultPostHogLabelProp, | ||
maxElementsCaptured = 20, | ||
ignoreLabels = [], | ||
propsToCapture = ['style', 'testID', 'accessibilityLabel', 'ph-label', 'children'], | ||
} = options | ||
const propsToCapture = ['style', 'testID', 'accessibilityLabel', customLabelProp, 'children'] | ||
|
||
if (!e._targetInst) { | ||
return | ||
|
@@ -105,16 +107,16 @@ export const autocaptureFromTouchEvent = (e: any, posthog: PostHog, options: Pos | |
} | ||
|
||
if (elements.length) { | ||
// The element that was tapped, may be a child (or grandchild of an element with a ph-label) | ||
// In this case, the current labels applied obscure the ph-label | ||
// To correct this, loop over the elements in reverse, and promote the ph-label | ||
// The element that was tapped, may be a child (or grandchild of an element with a customLabelProp (default: ph-label)) | ||
// In this case, the current labels applied obscure the customLabelProp (default: ph-label) | ||
// To correct this, loop over the elements in reverse, and promote the customLabelProp (default: ph-label) | ||
const elAttrLabelKey = `attr__${customLabelProp}` | ||
let lastLabel: string | undefined = undefined | ||
|
||
for (let i = elements.length - 1; i >= 0; i--) { | ||
const element = elements[i] | ||
if (element[elAttrLabelKey]) { | ||
// this element had a ph-label set, promote it to the lastLabel | ||
// this element had a customLabelProp (default: ph-label) set, promote it to the lastLabel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just iterate over normally here with early exit instead of reverse? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason why it is reversed is in the comment above. |
||
lastLabel = element[elAttrLabelKey] | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is chatgpt code :D