electerious / electerious/Ackee

Ackee counting unique page views on every page refresh

Open
#304 9 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
JavaScript
Stars
4.7k
Forks
384
PR merge metrics
No merged PRs in 30d

Description

Ackee counting unique page on every page refresh.
Using next.js with next following code in _app.tsx:

```jsx
import { Box, ChakraProvider, useColorModeValue } from '@chakra-ui/react'
import type { AppProps } from 'next/app'
import Head from 'next/head'
import { DefaultSeo } from 'next-seo'
import { getSeo } from 'lib/getSeo'
import customTheme from 'configs/theme'
import { EmotionCache } from '@emotion/cache'
import { CacheProvider } from '@emotion/react'
import createEmotionCache from 'lib/createEmotionCache'
import { useRouter } from 'next/router'
import { ackeeConfig } from 'configs/ackee-config'
import { useEffect, useMemo } from 'react'
import * as ackeeTracker from 'ackee-tracker'

interface MyAppProps extends AppProps {
emotionCache?: EmotionCache
}

const clientSideEmotionCache = createEmotionCache()
const { server, options, domainId } = ackeeConfig
function MyApp({
Component,
pageProps,
emotionCache = clientSideEmotionCache,
}: MyAppProps) {
const seo = getSeo()
const mode = useColorModeValue('light', 'dark')
const router = useRouter()

let instance: any = useMemo(() => {
if (typeof window !== 'undefined') {
return ackeeTracker.create(server, options)
}
}, [])

useEffect(() => {
const attributes = ackeeTracker.attributes(options.detailed)
const url = new URL(router.asPath, location as any)

const { stop } = instance.record(domainId, {
...attributes,
siteLocation: url.href,
})
return () => {
stop()
}
}, [router.asPath])

return (












)
}

export default MyApp

```

**⚙️ Environment**
- Installation: Vercel both app and ackee
- Ackee version: [e.g. v2.1.0]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.