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

clarity-js docs #606

Open
cloud-walker opened this issue May 20, 2024 · 4 comments
Open

clarity-js docs #606

cloud-walker opened this issue May 20, 2024 · 4 comments

Comments

@cloud-walker
Copy link

cloud-walker commented May 20, 2024

Hi all, I'm trying to use clarity-js instead of the official IIFE version, but I cannot find anywhere the docs on how to use it.

I'm missing something?

@tugbadeveloptica
Copy link

Hi all, I'm trying to use clarity-js instead of the official IIFE version, but I cannot find anywhere the docs on how to use it.

I'm missing something?

Hello, I want to use the repo in my project. Have you found a solution?

@cloud-walker
Copy link
Author

Hello after various trial and error, chatting with GPT I've baked something like that (is a React project):

import {clarity} from 'clarity-js'
import {useEffect} from 'react'

import {envVars} from '~/envVars'

export function Clarity() {
  useEffect(() => {
    if (!envVars.VITE_CLARITY_PROJECT_ID) {
      return
    }

    const handleVisibilityChange = () => {
      if (document.hidden || document.visibilityState === 'hidden') {
        clarity.pause()
      } else {
        clarity.resume()
      }
    }

    clarity.consent() // we actually dont need to wait for user consent here as we are on OMP
    clarity.identify('unknown')
    clarity.start({
      projectId: envVars.VITE_CLARITY_PROJECT_ID,
      upload: 'https://m.clarity.ms/collect',
      content: true,
      track: true,
    })

    document.addEventListener('visibilitychange', handleVisibilityChange)

    return () => {
      document.removeEventListener('visibilitychange', handleVisibilityChange)
      clarity.stop()
    }
  }, [])

  return null
}

@tugbadeveloptica
Copy link

Hello after various trial and error, chatting with GPT I've baked something like that (is a React project):

import {clarity} from 'clarity-js'
import {useEffect} from 'react'

import {envVars} from '~/envVars'

export function Clarity() {
  useEffect(() => {
    if (!envVars.VITE_CLARITY_PROJECT_ID) {
      return
    }

    const handleVisibilityChange = () => {
      if (document.hidden || document.visibilityState === 'hidden') {
        clarity.pause()
      } else {
        clarity.resume()
      }
    }

    clarity.consent() // we actually dont need to wait for user consent here as we are on OMP
    clarity.identify('unknown')
    clarity.start({
      projectId: envVars.VITE_CLARITY_PROJECT_ID,
      upload: 'https://m.clarity.ms/collect',
      content: true,
      track: true,
    })

    document.addEventListener('visibilitychange', handleVisibilityChange)

    return () => {
      document.removeEventListener('visibilitychange', handleVisibilityChange)
      clarity.stop()
    }
  }, [])

  return null
}

thankk you veryy much , i will definitelyy try it

@darrylhuffman
Copy link

Bump - where are the docs?!

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

No branches or pull requests

3 participants