Skip to content

Commit

Permalink
merge conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarticus committed Jun 23, 2024
2 parents 3ecd876 + 3017d39 commit 547e439
Show file tree
Hide file tree
Showing 26 changed files with 307 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bundled-size.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8.x.x

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
fetch-depth: 0
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x

Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4

- name: Set up Node.js
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label-version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
fetch-depth: 0

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand All @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand All @@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ssr-es-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testcafe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## 1.140.1 - 2024-06-21

- fix: unwind recent changes things seem less stable (#1267)

## 1.140.0 - 2024-06-21

- feat(web-analytics): Add property for autocapture link click (#1259)
- chore: add sanitization test to heatmaps tests (#1256)

## 1.139.8 - 2024-06-21

- fix(surveys branching): rename confirmation_message -> end (#1257)

## 1.139.7 - 2024-06-21

- fix(surveys): fix missing confirmation message state (#1263)

## 1.139.6 - 2024-06-20

- fix(surveys): handle missing getNextSurveyStep (#1260)

## 1.139.5 - 2024-06-20

- fix: Allow no capture of $opt_in event (#1250)

## 1.139.4 - 2024-06-20

- fix: no scheduled snapshots while idle (#1254)
- feat: Allow bootstrapping session id (#1251)

## 1.139.3 - 2024-06-18

- feat(surveys): add branching logic (#1247)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-js",
"version": "1.139.3",
"version": "1.140.1",
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
"repository": "https://github.com/PostHog/posthog-js",
"author": "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions playground/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function Home() {
<a className="Button" data-attr="autocapture-button" href="#">
<span>Autocapture a &gt; span</span>
</a>
<a href={'https://www.google.com'}>External link</a>

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

Expand Down
23 changes: 22 additions & 1 deletion src/__tests__/autocapture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ describe('Autocapture system', () => {
expect(props['$elements'][1]).toHaveProperty('tag_name', 'span')
expect(props['$elements'][2]).toHaveProperty('tag_name', 'div')
expect(props['$elements'][props['$elements'].length - 1]).toHaveProperty('tag_name', 'body')
expect(props['$external_click_url']).toEqual('https://test.com')
})

it('truncate any element property value to 1024 bytes', () => {
Expand Down Expand Up @@ -594,7 +595,27 @@ describe('Autocapture system', () => {
target: elTarget,
})
)
expect(captureMock.mock.calls[0][1]['$elements'][0]).toHaveProperty('attr__href', 'https://test.com')
const props = captureMock.mock.calls[0][1]
expect(props['$elements'][0]).toHaveProperty('attr__href', 'https://test.com')
expect(props['$external_click_url']).toEqual('https://test.com')
})

it('does not include $click_external_href for same site', () => {
window!.location = new URL('https://www.example.com/location') as unknown as Location
const elTarget = document.createElement('img')
const elParent = document.createElement('span')
elParent.appendChild(elTarget)
const elGrandparent = document.createElement('a')
elGrandparent.setAttribute('href', 'https://www.example.com/link')
elGrandparent.appendChild(elParent)
autocapture['_captureEvent'](
makeMouseEvent({
target: elTarget,
})
)
const props = captureMock.mock.calls[0][1]
expect(props['$elements'][0]).toHaveProperty('attr__href', 'https://www.example.com/link')
expect(props['$external_click_url']).toBeUndefined()
})

it('does not capture href attribute values from password elements', () => {
Expand Down
37 changes: 37 additions & 0 deletions src/__tests__/consent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ describe('consentManager', () => {
expect(posthog.persistence?.disabled).toBe(true)
})

describe('opt out event', () => {
let onCapture = jest.fn()
beforeEach(() => {
onCapture = jest.fn()
posthog = createPostHog({ opt_out_capturing_by_default: true, _onCapture: onCapture })
})

it('should send opt in event if not disabled', () => {
posthog.opt_in_capturing()
expect(onCapture).toHaveBeenCalledWith('$opt_in', expect.objectContaining({}))
})

it('should send opt in event with overrides', () => {
posthog.opt_in_capturing({
captureEventName: 'override-opt-in',
captureProperties: {
foo: 'bar',
},
})
expect(onCapture).toHaveBeenCalledWith(
'override-opt-in',
expect.objectContaining({
properties: expect.objectContaining({
foo: 'bar',
}),
})
)
})

it('should not send opt in event if null or false', () => {
posthog.opt_in_capturing({ captureEventName: null })
expect(onCapture).not.toHaveBeenCalled()
posthog.opt_in_capturing({ captureEventName: false })
expect(onCapture).not.toHaveBeenCalled()
})
})

describe('with do not track setting', () => {
beforeEach(() => {
;(navigator as any).doNotTrack = '1'
Expand Down
62 changes: 13 additions & 49 deletions src/__tests__/extensions/replay/sessionrecording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ describe('SessionRecording', () => {
})
})

it('emits full snapshot events even when idle', () => {
it('drops full snapshots when idle - so we must make sure not to take them while idle!', () => {
// force idle state
sessionRecording['isIdle'] = true
// buffer is empty
Expand All @@ -1335,21 +1335,15 @@ describe('SessionRecording', () => {

sessionRecording.onRRwebEmit(createFullSnapshot({}) as eventWithTime)

// custom event is buffered
expect(sessionRecording['buffer']).toEqual({
data: [
{
data: {},
type: 2,
},
],
data: [],
sessionId: sessionId,
size: 20,
size: 0,
windowId: 'windowId',
})
})

it('emits meta snapshot events even when idle', () => {
it('does not emit meta snapshot events when idle - so we must make sure not to take them while idle!', () => {
// force idle state
sessionRecording['isIdle'] = true
// buffer is empty
Expand All @@ -1361,23 +1355,15 @@ describe('SessionRecording', () => {

sessionRecording.onRRwebEmit(createMetaSnapshot({}) as eventWithTime)

// custom event is buffered
expect(sessionRecording['buffer']).toEqual({
data: [
{
data: {
href: 'https://has-to-be-present-or-invalid.com',
},
type: 4,
},
],
data: [],
sessionId: sessionId,
size: 69,
size: 0,
windowId: 'windowId',
})
})

it('emits style snapshot events even when idle', () => {
it('does not emit style snapshot events when idle - so we must make sure not to take them while idle!', () => {
// force idle state
sessionRecording['isIdle'] = true
// buffer is empty
Expand All @@ -1389,18 +1375,10 @@ describe('SessionRecording', () => {

sessionRecording.onRRwebEmit(createStyleSnapshot({}) as eventWithTime)

// custom event is buffered
expect(sessionRecording['buffer']).toEqual({
data: [
{
data: {
source: 13,
},
type: 3,
},
],
data: [],
sessionId: sessionId,
size: 31,
size: 0,
windowId: 'windowId',
})
})
Expand Down Expand Up @@ -1445,11 +1423,7 @@ describe('SessionRecording', () => {

// this triggers idle state and isn't a user interaction so does not take a full snapshot
emitInactiveEvent(thirdActivityTimestamp, true)
expect(_addCustomEvent).toHaveBeenCalledWith('sessionIdle', {
reason: 'user inactivity',
threshold: 300000,
timeSinceLastActive: 300900,
})

// event was not active so activity timestamp is not updated
expect(sessionRecording['_lastActivityTimestamp']).toEqual(firstActivityTimestamp)
expect(assignableWindow.rrweb.record.takeFullSnapshot).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -1481,10 +1455,7 @@ describe('SessionRecording', () => {

// this triggers exit from idle state _and_ is a user interaction, so we take a full snapshot
const fourthSnapshot = emitActiveEvent(fourthActivityTimestamp)
expect(_addCustomEvent).toHaveBeenCalledWith('sessionNoLongerIdle', {
reason: 'user activity',
type: INCREMENTAL_SNAPSHOT_EVENT_TYPE,
})

expect(sessionRecording['_lastActivityTimestamp']).toEqual(fourthActivityTimestamp)
expect(assignableWindow.rrweb.record.takeFullSnapshot).toHaveBeenCalledTimes(2)

Expand Down Expand Up @@ -1543,11 +1514,7 @@ describe('SessionRecording', () => {
// this triggers idle state and isn't a user interaction so does not take a full snapshot

emitInactiveEvent(thirdActivityTimestamp, true)
expect(_addCustomEvent).toHaveBeenCalledWith('sessionIdle', {
reason: 'user inactivity',
threshold: 300000,
timeSinceLastActive: 1799901,
})

// event was not active so activity timestamp is not updated
expect(sessionRecording['_lastActivityTimestamp']).toEqual(firstActivityTimestamp)
expect(assignableWindow.rrweb.record.takeFullSnapshot).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -1583,10 +1550,7 @@ describe('SessionRecording', () => {
// this triggers exit from idle state _and_ is a user interaction, so we take a full snapshot

const fourthSnapshot = emitActiveEvent(fourthActivityTimestamp)
expect(_addCustomEvent).toHaveBeenCalledWith('sessionNoLongerIdle', {
reason: 'user activity',
type: INCREMENTAL_SNAPSHOT_EVENT_TYPE,
})

expect(sessionRecording['_lastActivityTimestamp']).toEqual(fourthActivityTimestamp)
expect(assignableWindow.rrweb.record.takeFullSnapshot).toHaveBeenCalledTimes(2)

Expand Down
Loading

0 comments on commit 547e439

Please sign in to comment.