Skip to content

Commit

Permalink
Testing pageview event in vercel with app directory
Browse files Browse the repository at this point in the history
  • Loading branch information
4lejandrito committed May 18, 2024
1 parent 04e92ee commit d79a558
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions demo/app/app-directory-test/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function AppDirectoryTestPage() {
return 'This page should send a pageview event'
}
22 changes: 22 additions & 0 deletions demo/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PlausibleProvider from '../next-plausible/index.esm'

export default function RootLayout({ children }) {
const domain =
process.env.NODE_ENV === 'production'
? 'next-plausible.vercel.app'
: 'localhost:3000'
return (
<html lang="en">
<head>
<PlausibleProvider
domain={domain}
trackOutboundLinks
trackFileDownloads
enabled={domain.indexOf('localhost') !== -1 || undefined}
trackLocalhost={domain.indexOf('localhost') !== -1}
/>
</head>
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions demo/package-lock.json

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

20 changes: 20 additions & 0 deletions test/vercel/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ testPlausibleProvider((withPage) => {
)
}, 'https://next-plausible.vercel.app')

testPlausibleProvider((withPage) => {
describe(
'when used in a production deployment on vercel with the app directory',
withPage(
'/app-directory-test',
(_, getPage, events) => {
it('sends the pageview event', async () => {
await getPage().waitForNetworkIdle()
expect(events).toEqual([
expect.objectContaining({
n: 'pageview',
}),
])
})
},
'next-plausible.vercel.app'
)
)
}, 'https://next-plausible.vercel.app')

testPlausibleProvider((withPage) => {
describe(
'when used in a preview deployment on vercel',
Expand Down

0 comments on commit d79a558

Please sign in to comment.