Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ackee counting unique page views on every page refresh #304

Open
creotip opened this issue Dec 24, 2021 · 9 comments
Open

Ackee counting unique page views on every page refresh #304

creotip opened this issue Dec 24, 2021 · 9 comments

Comments

@creotip
Copy link

creotip commented Dec 24, 2021

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

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 (
    <CacheProvider value={emotionCache}>
      <ChakraProvider theme={customTheme}>
        <Head>
          <meta content="IE=edge" httpEquiv="X-UA-Compatible" />
          <meta content="width=device-width, initial-scale=1" name="viewport" />
          <link rel="icon" type="image/png" sizes="96x96" href="/favicon.png" />
          <meta
            name="google-site-verification"
            content="aTbQBMj8oiDmPHyuWHqMoxuv3NGKzHWCLV3rzlIJawo"
          />
          <Box
            as="meta"
            name="theme-color"
            content={mode === 'light' ? 'white' : '#141922'}
          />
        </Head>
        <DefaultSeo {...seo} />

        <Component {...pageProps} />
      </ChakraProvider>
    </CacheProvider>
  )
}

export default MyApp

⚙️ Environment

  • Installation: Vercel both app and ackee
  • Ackee version: [e.g. v2.1.0]
@CookedApps
Copy link

CookedApps commented Dec 26, 2021

Which version of Ackee do you use?
I have a similar problem, maybe it has something to do with it. See #305

@electerious
Copy link
Owner

This could have to do something with Vercel / serverless functions and the way Ackee generates the salt. A new one will be generated on every function invocation and the salt won't stay the same for the whole day like it does when used in a "normal" setup. I never thought about this and it's funny that no one complained about it so far.

I guess we need to find a way to generate a salt that is unique per day, but still different from user to user.

The current implementation: https://github.com/electerious/Ackee/blob/master/src/utils/salt.js

Ideas and PRs welcome.

@Feuerhamster
Copy link

We have a similar Issue with our site.
We invoke the instance.record method of the tracker every time a user navigates on our page.
In the Ackee dashboard, every single navigation from every user counts as a view.
This doesn't seem like expected behavior.

Where can we see our unique visitors?

@dottgonzo
Copy link

same for me. This is the first time i use ackee, and i'm experiencing that if i reload the page it do a +1 on unique views

@electerious
Copy link
Owner

Can confirm the issue. It doesn't seem to be a Vercel / serverless function only issue. Will take a closer look at it on the weekend. Help is welcome!

@electerious
Copy link
Owner

electerious commented Jan 15, 2022

Looks like we missed an important detail in the mongoose upgrade guide when we updated mongoose (#291). The unique visitor count and anonymisation is broken* since 3.2.0. I've pushed a fixed to the develop branch and will do some testing so I can release a hotfix tomorrow.

  • The visits were still anonymous, but Ackee tracked the visit path of each visitor. Data that Ackee usually removes.

The unique visitor count might still be broken in serverless environments and we need a better way to generate a daily, but unique salt: https://github.com/electerious/Ackee/blob/master/src/utils/salt.js

@mathe42
Copy link

mathe42 commented Jan 15, 2022

The unique visitor count might still be broken in serverless environments and we need a better way to generate a daily, but unique salt: https://github.com/electerious/Ackee/blob/master/src/utils/salt.js

We could just hash the current date concated with something instance specific (the ACKEE_USERNAME?) and some value hardcoded.

@electerious
Copy link
Owner

@mathe42 That could work. It just feels a bit weird to use ACKEE_USERNAME for that, but the salt is never exposed, so it shouldn't be a security issue. Maybe it's also an option to add something like ACKEE_SALT.

@electerious
Copy link
Owner

Fixed in v3.3.1 (for non serverless environments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants