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

dApp: PostHog integration #871

Merged
merged 13 commits into from
Dec 5, 2024
Merged

dApp: PostHog integration #871

merged 13 commits into from
Dec 5, 2024

Conversation

kpyszkowski
Copy link
Contributor

@kpyszkowski kpyszkowski commented Nov 16, 2024

Closes: #747
Closes: AENG-30

Overview

This PR integrates dApp with PostHog service to track users activities and analyze it. The PostHog project was created. All dApp activity is now accessible through the dashboard.
The API key and endpoint are available in the project settings.

Features

  • dApp integration using PostHog's official React SDK
  • Autocapture: all user interactions are tracked, any button click, any form fill
  • Manually triggered $pageview capture event: autocapture for page view event was disabled to prevent false positive captures. It is triggered manually as user visits the dApp.
  • User identification via wallet address
  • Added custom events with additional payload information:
    • deposit_success - payload: { transactionHash }
    • deposit_failure - payload: { cause }
    • withdrawal_success - wasn't able to easily get any reasonable payload here, can be done later
    • withdrawal_failure - payload: { cause }
    • points_claim_success - payload: { claimedAmount, totalAmount }
    • points_claim_failure - payload: { cause }
  • Defined feature flag to toggle PostHog integration

Changes

  • Added new env variables to define API key and endpoint and a feature flag
  • Defined preconfigured PostHogProvider to inject the service into application
  • Defined hooks: usePostHogCapture, usePostHogIdentity, usePostHogPageViewCapture
  • Integrated key actions to capture PostHog custom events (see above)

Caveats

To ensure the $pageview event is captured properly it's needed to call it as a side effect as the location value changes. To access this value (via useLocation hook) the router's context needs to be in scope of PostHog's context.
The only way to achieve it was to do it in the Layout component where both contexts are available.

Note

It's impossible to exclude captures for development environment. To keep data logs clean and ensure it contains only user's data I suggest to keep the feature flag disabled while using development environment.

@kpyszkowski kpyszkowski marked this pull request as draft November 16, 2024 02:21
Copy link

netlify bot commented Nov 16, 2024

Deploy Preview for acre-dapp ready!

Name Link
🔨 Latest commit 943d5da
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp/deploys/675188edf7ff4400080b1fdd
😎 Deploy Preview https://deploy-preview-871--acre-dapp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 16, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 943d5da
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/675188ed2103d7000885de35
😎 Deploy Preview https://deploy-preview-871--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kpyszkowski kpyszkowski mentioned this pull request Nov 16, 2024
@kpyszkowski kpyszkowski self-assigned this Nov 18, 2024
@kpyszkowski kpyszkowski marked this pull request as ready for review November 18, 2024 16:26
@kpyszkowski kpyszkowski requested review from r-czajkowski, kkosiorowska and nkuba and removed request for r-czajkowski and kkosiorowska November 18, 2024 16:26
@kpyszkowski kpyszkowski added the 🎨 dApp dApp label Nov 18, 2024
@kpyszkowski
Copy link
Contributor Author

@r-czajkowski

withdrawal_success - wasn't able to easily get any reasonable payload here, can be done later

Do you have any ideas about payload we could attach to the capture there? I mean something useful and available in the scope so can be used.

Copy link

linear bot commented Nov 27, 2024

@r-czajkowski
Copy link
Contributor

@kpyszkowski we should probably hash the Bitcoin address and then use it as ID, please see #904

@r-czajkowski
Copy link
Contributor

@r-czajkowski

withdrawal_success - wasn't able to easily get any reasonable payload here, can be done later

Do you have any ideas about payload we could attach to the capture there? I mean something useful and available in the scope so can be used.

Maybe we can add transactionHash and redemptionKey see https://github.com/thesis/acre/blob/main/sdk/src/modules/account.ts#L200.

@kpyszkowski
Copy link
Contributor Author

kpyszkowski commented Nov 28, 2024

@r-czajkowski

Maybe we can add transactionHash and redemptionKey

It's not that straight forward. I need to play around with mutation function to pass these parameters to callbacks.
Such change might affect whole withdrawal flow. I don't want to risk it. It's doable but let's not block the PR.

I prepared POC which looks fine for further investigation:
withdrawal-success-payload-poc.patch

r-czajkowski
r-czajkowski previously approved these changes Dec 5, 2024
Copy link
Contributor

@r-czajkowski r-czajkowski left a comment

Choose a reason for hiding this comment

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

Let's remember to set up correct env variables on testnet and production. I belive we should disable the posthog support on testnet.

@kpyszkowski
Copy link
Contributor Author

Updated environmental variables:

Mainnet (bitcoin.acre.fi) image
Testnet (bitcoin.test.acre.fi) image

@@ -26,5 +30,6 @@ VITE_FEATURE_FLAG_XVERSE_WALLET_ENABLED="false"
VITE_FEATURE_FLAG_ACRE_POINTS_ENABLED="true"
VITE_FEATURE_FLAG_TVL_ENABLED="true"
VITE_FEATURE_GATING_DAPP_ENABLED="true"
VITE_FEATURE_POSTHOG_ENABLED="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's disable by default.

Suggested change
VITE_FEATURE_POSTHOG_ENABLED="true"
VITE_FEATURE_POSTHOG_ENABLED="false"

@r-czajkowski r-czajkowski merged commit 1452d52 into main Dec 5, 2024
28 checks passed
@r-czajkowski r-czajkowski deleted the posthog branch December 5, 2024 11:11
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.

[Analytics] PostHog integration
2 participants