Skip to content

Commit

Permalink
feat: analyticsParams
Browse files Browse the repository at this point in the history
  • Loading branch information
phgrey committed Nov 7, 2024
1 parent 3fbc745 commit db6cbc3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion priv/tracker/js/plausible.live-view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tracker/src/plausible.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
if (window.liveSocket)
window.liveSocket.socket.logger = (kind, msg, data) => {
if ((kind === 'push') && !msg.includes("phoenix heartbeat")){
trigger('phx-push', {props: {msg, ...data}});
trigger('phx-push', {props: {msg, ...(window.analyticsParams || {}), ...data}});
}
}
else
Expand Down
13 changes: 13 additions & 0 deletions tracker/test/live-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ test.describe('script.live-view.js events', () => {
});

test('Sends phx-event', async ({ page }) => {
await page.evaluate(() => window.dispatchEvent(new CustomEvent("phx:page-loading-start", { })))
expectCustomEvent(await plausibleRequestMock, 'phx-event', { })
});

test('Sends phx-push', async ({ page }) => {
await page.evaluate(() => window.liveSocket.socket.logger('push', '_message', { a: 1 }))
expectCustomEvent(await plausibleRequestMock, 'phx-push', { a: 1 })
});

test('Sends analyticsParams', async ({ page }) => {
await page.evaluate(() => {
window.analyticsParams = { b: 2 };
window.liveSocket.socket.logger('push', '_message', { a: 1 });
})
expectCustomEvent(await plausibleRequestMock, 'phx-push', { a: 1, b: 2 })
});

test('Sends submit event', async ({ page }) => {
await (await page.locator("#main-form-btn")).click()
expectCustomEvent(await plausibleRequestMock, 'js-submit', { 'user[name]': "name", dom_id: "main-form" })
Expand Down

0 comments on commit db6cbc3

Please sign in to comment.