-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow config of before_send function to edit or reject events (#…
- Loading branch information
1 parent
5d8b45c
commit f4da6c8
Showing
21 changed files
with
941 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { start } from '../support/setup' | ||
import { isArray } from '../../src/utils/type-utils' | ||
|
||
describe('before_send', () => { | ||
it('can sample and edit with before_send', () => { | ||
start({}) | ||
|
||
cy.posthog().then((posthog) => { | ||
let counter = 0 | ||
const og = posthog.config.before_send | ||
// cypress tests rely on existing before_send function to capture events | ||
// so we have to add it back in here | ||
posthog.config.before_send = [ | ||
(cr) => { | ||
if (cr.event === 'custom-event') { | ||
counter++ | ||
if (counter === 2) { | ||
return null | ||
} | ||
} | ||
if (cr.event === '$autocapture') { | ||
return { | ||
...cr, | ||
event: 'redacted', | ||
} | ||
} | ||
return cr | ||
}, | ||
...(isArray(og) ? og : [og]), | ||
] | ||
}) | ||
|
||
cy.get('[data-cy-custom-event-button]').click() | ||
cy.get('[data-cy-custom-event-button]').click() | ||
|
||
cy.phCaptures().should('deep.equal', [ | ||
// before adding the new before sendfn | ||
'$pageview', | ||
'redacted', | ||
'custom-event', | ||
// second button click only has the redacted autocapture event | ||
'redacted', | ||
// because the second custom-event is rejected | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.