Browse Source

Use Plausible Analytics on nicegui.io (#4769)

Spiked by discussion #4746, this PR adds to our https://nicegui.io page:

- Plausible Analytics (wich is also used by FastAPI for their project
website)
- imprint & privacy page

---------

Co-authored-by: Falko Schindler <falko@zauberzeug.com>
Rodja Trappe 2 days ago
parent
commit
4b7dac612f
6 changed files with 65 additions and 1 deletions
  1. 1 0
      fly.dockerfile
  2. 6 1
      main.py
  3. 2 0
      website/documentation/rendering.py
  4. 6 0
      website/header.py
  5. 48 0
      website/imprint_privacy.py
  6. 2 0
      website/main_page.py

+ 1 - 0
fly.dockerfile

@@ -46,5 +46,6 @@ COPY fly-entrypoint.sh /entrypoint.sh
 ENTRYPOINT ["/entrypoint.sh"]
 
 ENV PYTHONUNBUFFERED=1
+ENV ENABLE_ANALYTICS=true
 
 CMD ["python", "main.py"]

+ 6 - 1
main.py

@@ -8,7 +8,7 @@ from fastapi.responses import RedirectResponse
 from starlette.middleware.sessions import SessionMiddleware
 
 from nicegui import app, ui
-from website import anti_scroll_hack, documentation, fly, main_page, svg
+from website import anti_scroll_hack, documentation, fly, imprint_privacy, main_page, svg
 
 # session middleware is required for demo in documentation
 app.add_middleware(SessionMiddleware, secret_key=os.environ.get('NICEGUI_SECRET_KEY', ''))
@@ -51,6 +51,11 @@ def _documentation_detail_page(name: str) -> Optional[RedirectResponse]:
     raise HTTPException(404, f'documentation for "{name}" could not be found')
 
 
+@ui.page('/imprint_privacy')
+def _imprint_privacy() -> None:
+    imprint_privacy.create()
+
+
 @app.get('/status')
 def _status():
     return 'Ok'

+ 2 - 0
website/documentation/rendering.py

@@ -72,6 +72,8 @@ def render_page(documentation: DocumentationPage, *, with_menu: bool = True) ->
                     documentation.extra_column()
         else:
             render_content()
+    with ui.column().classes('w-full p-4 items-end'):
+        ui.link('Imprint & Privacy', '/imprint_privacy').classes('text-sm')
 
 
 def _ancestor_nodes(node_id: str) -> List[str]:

+ 6 - 0
website/header.py

@@ -1,3 +1,4 @@
+import os
 from pathlib import Path
 from typing import Optional
 
@@ -14,6 +15,11 @@ STYLE_CSS = (Path(__file__).parent / 'static' / 'style.css').read_text(encoding=
 def add_head_html() -> None:
     """Add the code from header.html and reference style.css."""
     ui.add_head_html(HEADER_HTML + f'<style>{STYLE_CSS}</style>')
+    if os.environ.get('ENABLE_ANALYTICS', 'false').lower() == 'true':
+        ui.add_head_html(
+            '<script defer data-domain="nicegui.io" src="https://plausible.io/js/script.hash.outbound-links.js">'
+            '</script>'
+        )
 
 
 def add_header(menu: Optional[ui.left_drawer] = None) -> None:

+ 48 - 0
website/imprint_privacy.py

@@ -0,0 +1,48 @@
+from nicegui import ui
+from website.documentation.rendering import section_heading, subheading
+from website.header import add_head_html, add_header
+
+
+def create():
+    add_head_html()
+    add_header()
+    ui.page_title('Imprint & Privacy | NiceGUI')
+
+    with ui.column().classes('w-full p-8 lg:p-16 max-w-[1250px] mx-auto'):
+        section_heading('', 'Imprint')
+        subheading('Zauberzeug GmbH')
+        ui.markdown('''
+            Hohenholter Str. 43, 48329 Havixbeck, Germany
+
+            Represented by Rodion (Rodja) Trappe
+
+            Phone: +49 2507 3817, Email: info@zauberzeug.com
+        ''')
+
+        subheading('Registry entry')
+        ui.markdown('''
+            Registry court: Amtsgericht Coesfeld, Registry number: HRB 14215
+        ''')
+
+        subheading('Tax')
+        ui.markdown('''
+            Sales tax identification number according to §27a Sales Tax Act: DE286384205
+        ''')
+
+        section_heading('', 'Privacy Policy')
+        ui.markdown('''
+            We use [Plausible Analytics](https://plausible.io) to understand how you interact with our site.
+            Plausible Analytics is a privacy-first analytics tool
+            that does not use cookies or collect any personal data or personally identifiable information (PII).
+            All data collected by Plausible is aggregated and anonymized.
+
+            No other third-party analytics or tracking tools are used on this website.
+
+            These aggregated, non-identifiable usage statistics are processed on the basis
+            of our legitimate interest (Art. 6 (1)(f) GDPR) to analyze and improve our website.
+            You have the right to object to this processing at any time.
+            To exercise your right, please contact us at info@zauberzeug.com.
+
+            For more details on Plausible Analytics and its data policy,
+            visit <https://plausible.io/data-policy>.
+        ''')

+ 2 - 0
website/main_page.py

@@ -232,3 +232,5 @@ def create() -> None:
                         because of their great performance and ease of use.
                     ''')
             svg.face().classes('stroke-white shrink-0 w-[200px] md:w-[300px] lg:w-[450px]')
+        with ui.column().classes('w-full p-4 items-end text-white self-end'):
+            ui.link('Imprint & Privacy', '/imprint_privacy').classes('text-sm')