File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed
packages/analytics/src/server Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 11# Simple Analytics for Next.js
22
3-
43This package provides a simple way to add privacy-friendly pageview and event tracking using Simple Analytics to your Next.js application.
54
65## Documentation
@@ -48,7 +47,7 @@ export default function RootLayout({
4847 <html lang = " en" >
4948 <body >
5049 { children }
51- <SimpleAnalytics />
50+ <SimpleAnalytics />
5251 </body >
5352 </html >
5453 );
@@ -58,6 +57,7 @@ export default function RootLayout({
5857### Tracking events
5958
6059#### Usage in client components
60+
6161To start tracking programmatically tracking events in client components use the ` trackEvent ` function.
6262This requires the ` <SimpleAnalytics /> ` component to be present on the page or layout.
6363
@@ -84,7 +84,7 @@ export default function Page() {
8484
8585#### Usage in Server Actions
8686
87- To track events in server actions, use the ` trackEvent ` function from ` @simpleanalytics/next/server ` .
87+ To track events in server actions, use the ` trackEvent ` function from ` @simpleanalytics/next/server ` .
8888This function requires you to pass the request headers that can be obtained using ` headers ` .
8989
9090``` typescript
Original file line number Diff line number Diff line change @@ -38,7 +38,10 @@ export function parseUserAgent(headers: Headers) {
3838 return headers . get ( "User-Agent" ) ?? "" ;
3939}
4040
41- export function parseHeaders ( headers : Headers , ignoredMetrics : IgnoredMetrics = { } ) {
41+ export function parseHeaders (
42+ headers : Headers ,
43+ ignoredMetrics : IgnoredMetrics = { } ,
44+ ) {
4245 return {
4346 ua : ! ignoredMetrics . userAgent ? parseUserAgent ( headers ) : "" ,
4447
Original file line number Diff line number Diff line change 11import "server-only" ;
22
3- import {
3+ import type {
44 AnalyticsEvent ,
55 AnalyticsPageview ,
66 TrackingOptions ,
@@ -97,8 +97,10 @@ export async function trackPageview(options: TrackPageviewOptions) {
9797 event : "pageview" ,
9898 path,
9999 ...parseHeaders ( headers , options . ignoreMetrics ) ,
100- ...( searchParams
101- ? parseUtmParameters ( searchParams , { strictUtm : options . strictUtm ?? true } )
100+ ...( searchParams && ! options . ignoreMetrics ?. utm
101+ ? parseUtmParameters ( searchParams , {
102+ strictUtm : options . strictUtm ?? true ,
103+ } )
102104 : { } ) ,
103105 } ;
104106
You can’t perform that action at this time.
0 commit comments