Skip to content
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

feat(web-analytics): Add root $el_text #806

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions playground/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default function Home() {
<div className="buttons">
<button onClick={() => posthog.capture('Clicked button')}>Capture event</button>
<button data-attr="autocapture-button">Autocapture buttons</button>
<a data-attr="autocapture-button" href="#">
<span>Autocapture a &gt; span</span>
</a>

<button className="ph-no-capture">Ignore certain elements</button>

<button onClick={() => posthog?.identify('user-' + randomID())}>Identify</button>
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/autocapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,10 @@ describe('Autocapture system', () => {
autocapture._captureEvent(e1, lib)

const props1 = getCapturedProps(lib.capture)
expect(props1['$elements'][0]).toHaveProperty(
'$el_text',
const text1 =
"Some super duper really long Text with new lines that we'll strip out and also we will want to make this text shorter since it's not likely people really care about text content that's super long and it also takes up more space and bandwidth. Some super d"
)
expect(props1['$elements'][0]).toHaveProperty('$el_text', text1)
expect(props1['$el_text']).toEqual(text1)
lib.capture.resetHistory()

const e2 = {
Expand All @@ -899,6 +899,7 @@ describe('Autocapture system', () => {
autocapture._captureEvent(e2, lib)
const props2 = getCapturedProps(lib.capture)
expect(props2['$elements'][0]).toHaveProperty('$el_text', 'Some text')
expect(props2['$el_text']).toEqual('Some text')
lib.capture.resetHistory()

const e3 = {
Expand All @@ -908,6 +909,7 @@ describe('Autocapture system', () => {
autocapture._captureEvent(e3, lib)
const props3 = getCapturedProps(lib.capture)
expect(props3['$elements'][0]).toHaveProperty('$el_text', '')
expect(props3).not.toHaveProperty('$el_text')
})

it('does not capture sensitive text content', () => {
Expand Down
1 change: 1 addition & 0 deletions src/autocapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const autocapture = {
{
$elements: elementsJson,
},
elementsJson[0]?.['$el_text'] ? { $el_text: elementsJson[0]?.['$el_text'] } : {},
this._getCustomProperties(targetElementList),
autocaptureAugmentProperties
)
Expand Down
Loading