Example #1
0
def demo(request):
    user = request.user
    organization = user.organization
    try:
        team = organization.teams.get(name=TEAM_NAME)
    except Team.DoesNotExist:
        team = Team.objects.create_with_data(organization=organization,
                                             name=TEAM_NAME,
                                             ingested_event=True,
                                             completed_snippet_onboarding=True)
        _create_anonymous_users(team=team,
                                base_url=request.build_absolute_uri("/demo"))
        _create_funnel(team=team, base_url=request.build_absolute_uri("/demo"))
        _recalculate(team=team)
    user.current_team = team
    user.save()
    if "$pageview" not in team.event_names:
        team.event_names.append("$pageview")
        team.save()

    if is_ee_enabled():
        from ee.clickhouse.demo import create_anonymous_users_ch
        from ee.clickhouse.models.event import get_events_by_team

        result = get_events_by_team(team_id=team.pk)
        if not result:
            create_anonymous_users_ch(
                team=team, base_url=request.build_absolute_uri("/demo"))

    return render_template("demo.html",
                           request=request,
                           context={"api_token": team.api_token})
Example #2
0
def create_demo_team(organization: Organization, user: User, request: Request) -> Team:
    team = Team.objects.create_with_data(
        organization=organization, name=TEAM_NAME, ingested_event=True, completed_snippet_onboarding=True, is_demo=True,
    )
    _create_anonymous_users(team=team, base_url=request.build_absolute_uri("/demo"))
    _create_funnel(team=team, base_url=request.build_absolute_uri("/demo"))
    FeatureFlag.objects.create(
        team=team, rollout_percentage=100, name="Sign Up CTA", key="sign-up-cta", created_by=user,
    )
    _recalculate(team=team)

    if is_ee_enabled():
        from ee.clickhouse.demo import create_anonymous_users_ch

        create_anonymous_users_ch(team=team, base_url=request.build_absolute_uri("/demo"))

    return team
Example #3
0
def demo(request: Request):
    user = request.user
    organization = user.organization
    try:
        team = organization.teams.get(is_demo=True)
    except Team.DoesNotExist:
        team = create_demo_team(organization, user, request)
    user.current_team = team
    user.save()
    if "$pageview" not in team.event_names:
        team.event_names.append("$pageview")
        team.event_names_with_usage.append({"event": "$pageview", "usage_count": None, "volume": None})
        team.save()

    if is_ee_enabled():  # :TRICKY: Lazily backfill missing event data.
        from ee.clickhouse.demo import create_anonymous_users_ch
        from ee.clickhouse.models.event import get_events_by_team

        result = get_events_by_team(team_id=team.pk)
        if not result:
            create_anonymous_users_ch(team=team, base_url=request.build_absolute_uri("/demo"))

    return render_template("demo.html", request=request, context={"api_token": team.api_token})
Example #4
0
def demo(request):
    team = request.user.team
    if not Event.objects.filter(team=team).exists():
        _create_anonymous_users(team=team,
                                base_url=request.build_absolute_uri("/demo"))
        _create_funnel(team=team, base_url=request.build_absolute_uri("/demo"))
        _recalculate(team=team)
    if "$pageview" not in team.event_names:
        team.event_names.append("$pageview")
        team.save()

    if check_ee_enabled():
        from ee.clickhouse.demo import create_anonymous_users_ch
        from ee.clickhouse.models.event import get_events_by_team

        result = get_events_by_team(team_id=team.pk)
        if not result:
            create_anonymous_users_ch(
                team=team, base_url=request.build_absolute_uri("/demo"))

    return render_template("demo.html",
                           request=request,
                           context={"api_token": team.api_token})