File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ function setAllowTracking(on?: boolean) {
99 // opt_in_capturing() or opt_out_capturing() without having run
1010 // posthog.init() first. This generally only occurs when running locally.
1111 if ( window && process . env . NEXT_PUBLIC_POSTHOG_API_KEY ) {
12- if ( on ) {
12+ if ( on && ! posthog . has_opted_in_capturing ( ) ) {
1313 posthog . opt_in_capturing ( )
14- } else {
14+ // Make sure to capture initial page view after opting in
15+ posthog . capture ( '$pageview' )
16+ } else if ( ! on && ! posthog . has_opted_out_capturing ( ) ) {
1517 posthog . opt_out_capturing ( )
1618 }
1719 }
@@ -26,8 +28,7 @@ export function usePosthog() {
2628 api_host :
2729 process . env . NEXT_PUBLIC_POSTHOG_API_HOST ||
2830 'https://posthog.plural.sh' ,
29- opt_out_capturing_by_default :
30- window . Cookiebot ?. consent ?. statistics ?? false ,
31+ opt_out_capturing_by_default : ! window . Cookiebot ?. consent ?. statistics ,
3132 loaded : ( ) => {
3233 setAllowTracking ( window . Cookiebot ?. consent ?. statistics )
3334 } ,
You can’t perform that action at this time.
0 commit comments