mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
43bf7dd09f
* Use user-agent instead of screen_width to get device type Co-authored-by: eriknakata <erik.nakata5@gmail.com> * Fix credo * Log on unhandled UAInspector device type * Make 'browser' the default tab in devices report * Remove device tooltip * Remove screen_width from ingestion completely * Remove browserstack harness, run playwright directly * Select meta key based on OS platform * Run CI tests in parallel * Improve device match readability * Add changelog --------- Co-authored-by: eriknakata <erik.nakata5@gmail.com>
109 lines
4.3 KiB
JavaScript
109 lines
4.3 KiB
JavaScript
const { mockRequest, mockManyRequests, expectCustomEvent, metaKey } = require('./support/test-utils')
|
|
const { expect, test } = require('@playwright/test')
|
|
|
|
test.describe('tagged-events extension', () => {
|
|
test('tracks a tagged link click with custom props + url prop', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const linkURL = await page.locator('#link').getAttribute('href')
|
|
|
|
const plausibleRequestMock = mockRequest(page, '/api/event')
|
|
await page.click('#link')
|
|
expectCustomEvent(await plausibleRequestMock, 'Payment Complete', { amount: '100', method: "Credit Card", url: linkURL })
|
|
});
|
|
|
|
test('tracks a tagged form submit with custom props when submitting by pressing enter', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
const plausibleRequestMock = mockRequest(page, '/api/event')
|
|
|
|
const inputLocator = page.locator('#form-text-input')
|
|
await inputLocator.type('some input')
|
|
await inputLocator.press('Enter')
|
|
|
|
expectCustomEvent(await plausibleRequestMock, 'Signup', { type: "Newsletter" })
|
|
});
|
|
|
|
test('tracks submit on a form with a tagged parent when submit button is clicked', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const plausibleRequestMockList = mockManyRequests(page, '/api/event', 2)
|
|
|
|
await page.click('#submit-form-with-tagged-parent')
|
|
|
|
const requests = await plausibleRequestMockList
|
|
|
|
expect(requests.length).toBe(1)
|
|
expectCustomEvent(requests[0], "Form Submit", {})
|
|
});
|
|
|
|
test('tracks click and auxclick on any tagged HTML element', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const plausibleRequestMockList = mockManyRequests(page, '/api/event', 3)
|
|
|
|
await page.click('#button')
|
|
await page.click('#span')
|
|
await page.click('#div', { modifiers: [metaKey()] })
|
|
|
|
const requests = await plausibleRequestMockList
|
|
expect(requests.length).toBe(3)
|
|
requests.forEach(request => expectCustomEvent(request, 'Custom Event', { foo: "bar" }))
|
|
});
|
|
|
|
test('does not track elements without plausible-event-name class + link elements navigate', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
const linkLocator = page.locator('#not-tracked-link')
|
|
|
|
const linkURL = await linkLocator.getAttribute('href')
|
|
|
|
const plausibleRequestMock = mockRequest(page, '/api/event')
|
|
const navigationRequestMock = mockRequest(page, linkURL)
|
|
|
|
await page.click('#not-tracked-button')
|
|
await page.click('#not-tracked-span')
|
|
await linkLocator.click()
|
|
|
|
expect(await plausibleRequestMock, "should not have made Plausible request").toBeNull()
|
|
expect((await navigationRequestMock).url()).toContain(linkURL)
|
|
});
|
|
|
|
test('tracks tagged HTML elements when their child element is clicked', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const plausibleRequestMockList = mockManyRequests(page, '/api/event', 2)
|
|
|
|
await page.click('#h2-with-link-parent', { modifiers: [metaKey()] })
|
|
await page.click('#link-with-div-parent')
|
|
|
|
const requests = await plausibleRequestMockList
|
|
expect(requests.length).toBe(2)
|
|
requests.forEach(request => expectCustomEvent(request, 'Custom Event', { foo: "bar" }))
|
|
});
|
|
|
|
test('tracks tagged element that is dynamically added to the DOM', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const plausibleRequestMock = mockRequest(page, '/api/event')
|
|
|
|
const buttonLocator = page.locator('#dynamic-tagged-button')
|
|
await buttonLocator.waitFor({state: 'visible'})
|
|
await page.waitForTimeout(500)
|
|
|
|
await buttonLocator.click()
|
|
|
|
expectCustomEvent(await plausibleRequestMock, 'Custom Event', {})
|
|
});
|
|
|
|
test('does not track clicks inside a tagged form, except submit click', async ({ page }) => {
|
|
await page.goto('/tagged-event.html')
|
|
|
|
const plausibleRequestMock = mockRequest(page, '/api/event')
|
|
|
|
await page.click('#form')
|
|
await page.click('#form-input')
|
|
await page.click('#form-div')
|
|
|
|
expect(await plausibleRequestMock, "should not have made Plausible request").toBeNull()
|
|
});
|
|
});
|