Skip to content

feat(demo-mode): analytics #89720

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

Merged
merged 8 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sentry/templates/sentry/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load sentry_features %}
{% load sentry_helpers %}
{% load sentry_status %}
{% load sentry_demo_mode %}
{% get_sentry_version %}
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -70,6 +71,9 @@
{% asset_url 'sentry' 'js/ads.js' as asset_url %}
{% script src=asset_url crossorigin="anonymous" %}{% endscript %}
{% endblock %}

{% init_demo_analytics request.get_host %}

</head>


Expand Down
18 changes: 18 additions & 0 deletions src/sentry/templatetags/sentry_demo_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import template
from django.utils.safestring import mark_safe

from sentry.demo_mode.utils import is_demo_mode_enabled

register = template.Library()


@register.simple_tag
def init_demo_analytics(domain):
if not is_demo_mode_enabled():
return ""

html = f"""
<script defer data-domain="{domain}" src="https://plausible.io/js/script.pageview-props.tagged-events.js"></script>
<script>window.plausible = window.plausible || function() {{ (window.plausible.q = window.plausible.q || []).push(arguments) }}</script>
"""
return mark_safe(html)
31 changes: 0 additions & 31 deletions static/app/utils/demoMode/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Sentry from '@sentry/react';

import {setForceHide} from 'sentry/actionCreators/guides';
import {demoSignupModal} from 'sentry/actionCreators/modal';
import type {Client} from 'sentry/api';
Expand All @@ -25,7 +23,6 @@ export function initDemoMode(api: Client) {
if (!isDemoModeActive()) {
return;
}
initDemoAnalytics();
captureEmail(api);
}

Expand Down Expand Up @@ -57,31 +54,3 @@ async function captureEmail(api: Client) {
setForceHide(false);
}
}

function initDemoAnalytics() {
if (!isDemoModeActive()) {
return;
}

if (document.getElementById('plausible-script')) {
return;
}

try {
const mainScript = document.createElement('script');
mainScript.id = 'plausible-script';
mainScript.defer = true;
mainScript.setAttribute('data-domain', window.location.hostname);
mainScript.src = 'https://plausible.io/js/script.pageview-props.tagged-events.js';

const queueScript = document.createElement('script');
queueScript.id = 'plausible-queue-script';
queueScript.textContent =
'window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }';

document.head.appendChild(mainScript);
document.head.appendChild(queueScript);
} catch (error) {
Sentry.captureException(error);
}
}
Loading