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: adding posthog libs for node + js #16862

Merged

Conversation

abhi-slash-git
Copy link
Contributor

What does this PR do?

  • Adds posthog node + js libs for event tracking.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

Copy link

vercel bot commented Sep 27, 2024

@abhi-slash-git is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Sep 27, 2024
@graphite-app graphite-app bot requested review from a team September 27, 2024 15:28
@CLAassistant
Copy link

CLAassistant commented Sep 27, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the ❗️ .env changes contains changes to env variables label Sep 27, 2024
@dosubot dosubot bot added insights area: insights, analytics ✨ feature New feature or request labels Sep 27, 2024
Copy link

graphite-app bot commented Sep 27, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (09/27/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add foundation team as reviewer" took an action on this PR • (09/27/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (09/27/24)

1 label was added to this PR based on Keith Williams's automation.

@abhi-slash-git abhi-slash-git marked this pull request as draft September 27, 2024 15:30
@abhi-slash-git
Copy link
Contributor Author

@sean-brydon PR created, would like your help with the frontend setup. Thank you

@sean-brydon
Copy link
Member

@sean-brydon PR created, would like your help with the frontend setup. Thank you

Posthog is now initializing on the frontend and saving page views.

We should think when we want to call the identify function on the user - in shell was re-rendering too much. Maybe we do this upon login?

@abhi-slash-git
Copy link
Contributor Author

@sean-brydon Yep you are right, we can do this on login. We also have to remember to do call reset() on logout as well.

organization: data?.organization?.slug,
sum_of_event_types: data?.sumOfEventTypes,
sum_of_team_event_types: data?.sumOfTeamEventTypes,
is_premium: data?.isPremium,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sean-brydon check which properties to remove

@abhi-slash-git abhi-slash-git marked this pull request as ready for review October 7, 2024 14:36
@abhi-slash-git
Copy link
Contributor Author

@sean-brydon bump for visibilty

Copy link
Contributor

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Oct 26, 2024
Copy link
Contributor

github-actions bot commented Nov 1, 2024

E2E results are ready!

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Nov 2, 2024 2:44am
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Nov 2, 2024 2:44am

Copy link
Member

@sean-brydon sean-brydon left a comment

Choose a reason for hiding this comment

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

LGTM - will see if someone else can have some eyes as i did a bit of work on this also

Copy link
Contributor

@baileypumfleet baileypumfleet left a comment

Choose a reason for hiding this comment

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

Code looks good to me

Thank you for your help on this :)

useEffect(() => {
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) return;
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://us.i.posthog.com",
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though we use the EU PostHog region, we can keep the US one as the fallback

@baileypumfleet baileypumfleet enabled auto-merge (squash) November 2, 2024 02:43
@baileypumfleet baileypumfleet added ❗️ .env changes contains changes to env variables and removed ❗️ .env changes contains changes to env variables labels Nov 2, 2024
@baileypumfleet
Copy link
Contributor

@abhi-slash-git could you sign the CLA real quick? You should see it as the second comment on this PR

@keithwillcode keithwillcode added this to the v4.7 milestone Nov 3, 2024
@baileypumfleet baileypumfleet merged commit ddfbe25 into calcom:main Nov 4, 2024
32 of 36 checks passed
@neuhaus
Copy link

neuhaus commented Nov 6, 2024

Building the docker container with this change applied fails for me as follows:

   Linting and checking validity of types ...
Failed to compile.

../../packages/features/ee/event-tracking/lib/posthog/web/PostHogPageView.tsx:15:11
Type error: 'searchParams' is possibly 'null'.

  13 |     if (pathname && posthog) {
  14 |       let url = window.origin + pathname;
> 15 |       if (searchParams.toString()) {
     |           ^
  16 |         url = `${url}?${searchParams.toString()}`;
  17 |       }
  18 |       posthog.capture("$pageview", {
The command '/bin/sh -c yarn --cwd apps/web workspace @calcom/web run build' returned a non-zero code: 1

@neuhaus
Copy link

neuhaus commented Nov 6, 2024

i guess changing the line to
if (searchParams?.toString()) {
will fix the issue?

@neuhaus
Copy link

neuhaus commented Nov 7, 2024

@abhi-slash-git i don't understand why you didn't have this issue during building

@abhi-slash-git
Copy link
Contributor Author

@sean-brydon might know, I believe he added this change

@zomars
Copy link
Member

zomars commented Nov 12, 2024

@neuhaus @abhi-slash-git @sean-brydon this is now causing issues locally. I'm getting the same errors when building locally.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Created by Linear-GitHub Sync ❗️ .env changes contains changes to env variables ✨ feature New feature or request insights area: insights, analytics ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants