Skip to content

Conversation

Twixes
Copy link
Member

@Twixes Twixes commented Dec 22, 2021

Changes

This adds a new mode of operation to the app: PostHog Demo™.
Enabled with env var DEMO, it merges the normal signup and login flows into a "demo signin", i.e. you create an account without a password (when you first enter the demo environment with that email) and log in also without a password (if entering with an already used email). On account creation, you're plopped into a fresh demo project. The announcement bar at the top shows a special demo mode message. As for analytics, demo mode is a new realm (to track it while distinguishing it from production instances): demo.

Demo of the demo:
demo demo

How did you test this code?

Spun up a PostHog Demo™ instance with the hobby script, available at https://demo.posthog.com (just as a proof of concept, will need to move away from my personal DigitalOcean account later on).

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

Found some things to nit about, but looks good.

The only question I have is if we actually want to enable this? Probably, but then we must make sure it's always up to date with some playable data. Enabling the "make some noise" plugin might be enough even?

Comment on lines 47 to 73
is_instance_first_user: bool = not User.objects.exists()
already_existing_demo_user = (
None if not settings.DEMO else User.objects.filter(email=validated_data["email"]).first()
)

organization_name = validated_data.pop("organization_name", validated_data["first_name"])
if not already_existing_demo_user:
# Normal signup flow
is_instance_first_user: bool = not User.objects.exists()

organization_name = validated_data.pop("organization_name", validated_data["first_name"])
if settings.DEMO:
validated_data["password"] = None

self._organization, self._team, self._user = User.objects.bootstrap(
organization_name=organization_name,
create_team=self.create_team,
**validated_data,
is_staff=is_instance_first_user,
)
else:
# If there's an email collision in signup in the demo environment, we treat it as a login
is_instance_first_user = False

self._user = already_existing_demo_user
self._organization = already_existing_demo_user.organization
self._team = already_existing_demo_user.team
Copy link
Collaborator

Choose a reason for hiding this comment

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

A nit perhaps, but could this be refactored to:

if settings.DEMO:
    # override everything
else:
    # normal flow

It's kind of hard to follow along, and such critical code as the signup flow should be made as mistake-proof as possible. Maybe already just flipping the if if not already_existing_demo_user: to if already_existing_demo_user: will make this cleaner?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, refactored the demo handling to method enter_demo().

posthog/utils.py Outdated
"""
if settings.MULTI_TENANCY:
return "cloud"
if settings.DEMO:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nittiest of nits, but if -> elif to keep tactical formation.

@jamesefhawkins
Copy link
Collaborator

I've left some comments on why I think we can't make this somewhere users go yet

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@guidoiaquinti
Copy link
Contributor

Overall LGTM but I'll appreciate also another pair of 👀 from someone of my team. Also, what's the long term plan for this? Do we have a plan to make sure:

  • the instance is up-to-date
  • we have proper monitoring/alerting setup
  • etc..

Thank you!

Copy link
Contributor

@tiina303 tiina303 left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines 23 to 24
<a href="https://posthog.com/signup/self-host">easily deploy PostHog yourself</a> or{' '}
<a href="https://app.posthog.com/signup">sign up for a free PostHog Cloud account</a>.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: https://posthog.com/signup covers both self-hosting and cloud and we should likely just redirect them there, and that page can evolve and give all the guidance. "easily deploy" might mislead folks to thinking it's easier to self-host compared to cloud, which isn't true. Related Q: do we want that page to highlight the option to check out the demo too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, simplified to a single link to that "Get started" page with copy "deploy your own PostHog instance or sign up for PostHog Cloud". I think if we go forward with the demo env, it should be somewhere on the website, but the homepage seems like the clearest place to expose it, so I'll stay with that for now (PostHog/posthog.com#2661).

@Twixes
Copy link
Member Author

Twixes commented Jan 3, 2022

Good questions @guidoiaquinti I don't have a great story for deployment yet (the current MVP at demo.posthog.com rans with the hobby script), but it can be just a self-hosted PostHog instance (probably AWS or DO) pinned to posthog/posthog:latest – the only difference from a production instance being env var DEMO=1 (talk about dogfooding!). Should be pretty simple to make the instance redeploy when latest is updated, or maybe even just once a day to keep things light. I don't think alerting is a blocker here, but should we ever want it, the instrumentation is the same as Cloud.

@Twixes Twixes merged commit 365d7b2 into master Jan 3, 2022
@Twixes Twixes deleted the demo branch January 3, 2022 18:40
@tiina303
Copy link
Contributor

tiina303 commented Jan 4, 2022

Should be pretty simple to make the instance redeploy when latest is updated, or maybe even just once a day to keep things light.

yes it's simple for the deployment side. I'd suggest following latest the same as cloud (which likely means you'll want to have the workflow in this repo). I'd pick DO since it's the easiest to manage, the values file should likely live in the vpc repo (so we can define stuff we don't want public, e.g sentry, google sign on). Reach out in the platform channel if we can help with anything.

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.

6 participants