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

feat: product analytic UI #4262

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open

feat: product analytic UI #4262

wants to merge 10 commits into from

Conversation

urmauur
Copy link
Member

@urmauur urmauur commented Dec 11, 2024

Describe Your Changes

  • Permission pop-up
    CleanShot 2024-12-11 at 13 58 54

  • Privacy setting
    CleanShot 2024-12-11 at 13 59 52

  • Integrate posthog
    Screenshot 2024-12-11 at 14 01 56

if (typeof window !== 'undefined') {
  posthog.init(POSTHOG_KEY, {
    api_host: POSTHOG_HOST,
    autocapture: false,
    person_profiles: 'always',
    persistence: 'localStorage',
  });
}

Initializes PostHog only on the client side (browser environment) to avoid errors during server-side rendering.

  • PostHog is configured with the following options:
  • api_host: Specifies the PostHog API endpoint.
  • autocapture: false: Disables automatic event tracking; events need to be explicitly tracked.
  • person_profiles: 'always': Enables person profiles in all cases.
  • persistence: 'localStorage': Ensures data is stored in localStorage for consistency across browser sessions.
useEffect(() => {
  const timer = setTimeout(() => {
    if (productAnalyticPrompt) {
      setShowProductAnalyticPrompt(true);
    }
    return () => clearTimeout(timer);
  }, 3000); // 3 seconds delay

  return () => clearTimeout(timer); // Cleanup timer on unmount
}, [productAnalyticPrompt]
  • Adds a delay of 3 seconds before showing a product analytics prompt (setShowProductAnalyticPrompt(true)).

  • Uses a setTimeout inside the useEffect and ensures cleanup with clearTimeout:

    • First cleanup ensures the timeout is cleared when productAnalyticPrompt changes or the component unmounts.
    • Second cleanup ensures proper memory management if the timeout runs its course.
    • This ensures no unnecessary timers are left running, avoiding potential performance issues.
    useEffect(() => {
    if (productAnalytic) {
      posthog.opt_in_capturing();
      posthog.register({ app_version: VERSION });
    } else {
      posthog.opt_out_capturing();
    }
    

}, [productAnalytic]);


- Handles user consent (productAnalytic) to enable or disable analytics tracking:
- If consent is given (productAnalytic is true):
  - Enables tracking using posthog.opt_in_capturing().
  - Registers additional data like app_version with PostHog.
- If consent is not given (productAnalytic is false):
  - Disables tracking using posthog.opt_out_capturing().
  - Dependency on productAnalytic ensures this effect runs whenever consent changes.

## Fixes Issues

- Closes #3119 
- Closes #

## Self Checklist

- [ ] Added relevant comments, esp in complex areas
- [ ] Updated docs (for bug fixes / features)
- [ ] Created issues for follow-up changes or refactoring needed

@urmauur urmauur added the type: feature request A new feature label Dec 11, 2024
@urmauur urmauur added this to the v0.5.12 milestone Dec 11, 2024
@urmauur urmauur self-assigned this Dec 11, 2024
luiyen
luiyen approved these changes Dec 11, 2024
Copy link
Contributor

@louis-jan louis-jan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

github-actions bot commented Dec 11, 2024

Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

Copy link
Collaborator

@hiento09 hiento09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

This is the build for this pull request. You can download it from the Artifacts section here: Build URL.

@urmauur urmauur force-pushed the feat/product-analytic-ui branch from ee26bdd to bb18f84 Compare December 13, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants