mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
# Conflicts: # .github/workflows/check-insights-major-version.yml # .github/workflows/check-posthog-major-version.yml # .github/workflows/ci-security.yaml # .github/workflows/validate-versioning.yml # AGENTS.md # AGENTS.md~upstream_main # packages/ai/src/otel/capture.ts # packages/ai/src/otel/mappers/aiSdk.ts # packages/ai/src/otel/mappers/index.ts # packages/ai/src/otel/types.ts # packages/core/src/__tests__/posthog.init.spec.ts # packages/react-native/src/PostHogProvider.tsx # packages/react/src/context/PostHogContext.ts # packages/react/src/context/PostHogProvider.tsx # tooling/eslint-plugin-insights/no-unsafe-web-global.js
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { expect, test } from './utils/insights-playwright-test-base'
|
|
import { start } from './utils/setup'
|
|
import { Insights } from '@/insights-core'
|
|
|
|
test.describe('group analytics', () => {
|
|
test('includes group information in all event payloads', async ({ page, context }) => {
|
|
await start(
|
|
{
|
|
runBeforeInsightsInit: async (page) => {
|
|
// it's tricky to pass functions as args the way insights config is passed in playwright
|
|
// so here we set the function on the window object
|
|
// and then call it in the loaded function during init
|
|
await page.evaluate(() => {
|
|
;(window as any).__ph_loaded = (ph: Insights) => {
|
|
ph.group('company', 'id:5')
|
|
}
|
|
})
|
|
},
|
|
},
|
|
page,
|
|
context
|
|
)
|
|
|
|
await page.locator('[data-cy-custom-event-button]').click()
|
|
|
|
const capturedEvents = await page.capturedEvents()
|
|
// 4 events: $groupidentify (from group() call), $pageview, $pageleave, custom event
|
|
expect(capturedEvents).toHaveLength(4)
|
|
const hasGroups = new Set(capturedEvents.map((x) => !!x.properties.$groups))
|
|
expect(hasGroups).toEqual(new Set([true]))
|
|
})
|
|
})
|