PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
20.6k stars 1.23k forks source link

Add `page` function to all libraries #635

Open timgl opened 4 years ago

timgl commented 4 years ago

Is your feature request related to a problem? Please describe. I want to easily be able to capture pageviews. At the moment, in all libraries I need to do posthog.capture('$pageview', {'$current_url': 'https://...'}).

Describe the solution you'd like I want to be able to do posthog.page('https://...')

Additional context

Thank you for your feature request - we love each and every one!

mariusandra commented 4 years ago

I think we should also add screen to all the libraries. We'll never know for example if the Python app is used for a website... or a game... or in a mobile app using PyMob... or whatever else someone comes up with one day.

I'd then also add page to the iOS and Android libraries following the same logic... and just to keep things consistent.

thisHermit commented 4 years ago

Hey @timgl , this seems to be one line function in all libraries. Is this the brief description of it or is there some nuance involved?

timgl commented 4 years ago

Nope, this is it! It's fairly simple, just involves doing PRs in all the libraries :)

thisHermit commented 4 years ago

Could you assign me to this issue?

timgl commented 4 years ago

Done!

paolodamico commented 2 years ago

@yakkomajuri do we want to move forward with this?

Aashish-Upadhyay-101 commented 1 year ago

hey is this available I want to work on this and also need some guide coz this is my first time ever contributing to Posthog

thinklinux commented 1 year ago

Hey @timgl can I take this one if it is still valid?

I see in the documentation that all it has to be done now is posthog.capture('$pageview') as a shortcut and it will automatically send the current url. Is this good enough or do we want a more explicit method like page?

marandaneto commented 6 months ago

Mobile has a screen method with an event called $screen and a property called $screen_name, this is available on android, ios, flutter and RN.

anirudh24seven commented 5 days ago

@timgl I have raised a PR for the JS library along with tests. Will take it up with the maintainers of each library for the best practices in each of them.

Meanwhile, I want to confirm the following:

  1. It makes sense to make this changes in all the libraries at the same time
  2. This is the list of languages in which we'll be adding this functionality (Next.js, Android, Elixir, Flutter, Go, iOS, Java, node.js, PHP, JS Web, Python, React, Ruby, Rust, React Native)

https://posthog.com/docs/libraries

Screenshot 2024-09-03 at 9 36 24 AM

I will be proceeding with the above assumptions. Please let me know if there is anything else to take care of.

anirudh24seven commented 4 days ago

Looks like this is already implemented in the Python library: https://github.com/PostHog/posthog-python/blob/master/posthog/client.py#L325

marandaneto commented 4 days ago

Looks like this is already implement in the Python library: PostHog/posthog-python@master/posthog/client.py#L325

Mobile SDKs don't need a page method since they have the screen method already

anirudh24seven commented 4 days ago

https://github.com/PostHog/posthog-java/pull/61#issuecomment-2328355673

As mentioned by @marandaneto :

I dont think this makes sense in backend SDKs including this one. This is only for UI/frontend SDKs.

This would mean the Next.js, JS Web and the React libraries. Is that correct?

anirudh24seven commented 4 days ago

This would mean the Next.js, JS Web and the React libraries. Is that correct?

It looks like the React library internally uses posthog-js as well.

Also, the Next.js integration documentation clearly talks about using the React and Node.js SDKs.

I would then assume that the original PR is the only required effort needed for this issue.

marandaneto commented 4 days ago

yes, and they are all under https://github.com/postHog/posthog-js since they are just frameworks supported by this SDK