Track user sessions and analytics natively in Bubble by creating a Session Log data type that records page views, button clicks, and session durations. This tutorial shows how to build a lightweight in-app analytics system using workflows and display the data on an admin dashboard with charts.
Overview: User Session Tracking in Bubble
This tutorial builds a native analytics system inside your Bubble app. Instead of relying solely on Google Analytics or third-party tools, you will log user activity directly to your database — giving you full control over what you track and how you display it. This is ideal for non-technical founders who want to understand user behavior without leaving the Bubble ecosystem.
Prerequisites
- A Bubble account with an app that has user authentication
- At least one page with interactive elements (buttons, links)
- Basic understanding of Data Types and Workflows
- Familiarity with Repeating Groups for displaying data
Step-by-step guide
Create the Session Log data type
Create the Session Log data type
Go to the Data tab and click 'New type.' Name it 'SessionLog.' Add the following fields: 'user' (type: User), 'page_name' (type: text), 'action_type' (type: text — e.g., 'page_view', 'button_click'), 'action_detail' (type: text — e.g., the button name), 'session_start' (type: date), and 'session_end' (type: date). This data type will store every tracked interaction.
Pro tip: Create an Option Set called 'ActionType' with options like page_view, button_click, form_submit, and link_click to keep your action_type values consistent.
Expected result: A SessionLog data type appears in your Data tab with all the specified fields.
Record page views on every page load
Record page views on every page load
Go to the Workflow tab on your main page. Add a new event: 'Page is loaded.' Add an action: 'Create a new thing' → Type: SessionLog. Set the fields: user = Current User, page_name = Current page name (or a static text like 'Dashboard'), action_type = 'page_view', session_start = Current date/time. Copy this workflow to every page in your app where you want tracking.
Expected result: Every time a logged-in user visits a page, a new SessionLog record is created.
Track button clicks with workflow actions
Track button clicks with workflow actions
Select a key button on your page — for example, a 'Submit' or 'Add to Cart' button. Go to its workflow and add a new action at the beginning: 'Create a new thing' → Type: SessionLog. Set: user = Current User, page_name = Current page name, action_type = 'button_click', action_detail = 'Submit Button' (use a descriptive static text for the button). Repeat for other important buttons you want to track.
Pro tip: Add the tracking action as the first step in existing button workflows so it fires even if later steps fail.
Expected result: Clicking tracked buttons creates SessionLog records with the button name in action_detail.
Calculate session duration using page unload
Calculate session duration using page unload
To track how long users stay on a page, modify your Page is loaded workflow. After creating the SessionLog, add an action: 'Set state of index' → State: current_session (type: SessionLog) = Result of step 1. Then add a second workflow event: 'Do when condition is true' → When Current User is logged out (or use a 'Page is navigated away' custom event). In that workflow, add: 'Make changes to a thing' → Thing: index's current_session → session_end = Current date/time.
Expected result: Each SessionLog record captures both start and end times, letting you calculate duration.
Build an admin analytics dashboard
Build an admin analytics dashboard
Create a new page called 'admin-analytics.' Add a Repeating Group with data source: Do a search for SessionLog, sorted by Created Date descending. Display columns for user email, page_name, action_type, action_detail, and session_start. Above the Repeating Group, add summary elements: a Text element showing 'Total page views: ' followed by Do a search for SessionLog (constraint: action_type = page_view) :count. Add a date range picker to filter the search by Created Date.
Pro tip: Use Bubble's Chart element (from the Chart.js plugin) to visualize daily page views as a line chart.
Expected result: An admin page displays a table of all user activity with summary counts and optional charts.
Add privacy rules to protect analytics data
Add privacy rules to protect analytics data
Go to Data tab → Privacy. Click on SessionLog. Add a rule: 'When Current User's role is admin' → grant all permissions (Find in searches, View all fields). For all other users, they should only be able to create new SessionLog records but not view others' data. This prevents regular users from accessing the analytics dashboard data.
Expected result: Only admin users can view the analytics dashboard data. Regular users can still create tracking records.
Complete working example
1USER SESSION TRACKING — WORKFLOW SUMMARY2=========================================34DATA TYPE: SessionLog5 Fields:6 - user (User)7 - page_name (text)8 - action_type (text) — page_view, button_click, form_submit9 - action_detail (text) — specific element name10 - session_start (date)11 - session_end (date)1213WORKFLOW 1: Track Page View14 Event: Page is loaded15 Condition: Current User is logged in16 Action 1: Create a new thing → SessionLog17 - user = Current User18 - page_name = "Dashboard" (or Current page name)19 - action_type = "page_view"20 - session_start = Current date/time21 Action 2: Set state of index → current_session = Result of step 12223WORKFLOW 2: Track Button Click24 Event: When [Button] is clicked25 Action 1: Create a new thing → SessionLog26 - user = Current User27 - page_name = Current page name28 - action_type = "button_click"29 - action_detail = "Add to Cart Button"30 - session_start = Current date/time3132WORKFLOW 3: Record Session End33 Event: Do when condition is true (Current User is logged out)34 Action: Make changes to index's current_session35 - session_end = Current date/time3637ADMIN DASHBOARD:38 Repeating Group: Do a search for SessionLog, sorted by Created Date desc39 Summary: SessionLog search (action_type = page_view) :count40 Chart: daily counts grouped by Created Date4142PRIVACY RULES:43 SessionLog:44 - Admin users: full access45 - All users: create onlyCommon mistakes when implementing user session tracking for analytics in Bubble.io: Step-by-Step
Why it's a problem: Tracking every single user action and creating too many database records
How to avoid: Track only key actions — page views and important button clicks. Use a backend workflow to purge old records monthly.
Why it's a problem: Not adding privacy rules to the SessionLog data type
How to avoid: Add a privacy rule that restricts find-in-searches and view-all-fields to admin users only
Why it's a problem: Forgetting to handle logged-out users
How to avoid: Add an Only when condition to tracking workflows: Current User is logged in. For anonymous tracking, use a cookie or URL parameter instead.
Best practices
- Track only the most important user actions to minimize workload unit consumption
- Use an Option Set for action types to keep tracking data consistent and filterable
- Schedule a recurring backend workflow to archive or delete SessionLog records older than 90 days
- Add date range filters to your admin dashboard to avoid loading all records at once
- Use privacy rules to restrict analytics data to admin users only
- Consider using Google Analytics alongside native tracking for SEO and acquisition data
- Group analytics queries with the :group by operator for summary charts instead of loading raw records
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I want to build a user activity tracking system in my Bubble.io app. I need to log page views, button clicks, and session durations in a database table, then display the data on an admin dashboard with charts. Can you outline the data structure and workflows?
Create a user session tracking system for my app. Add a SessionLog data type with fields for user, page name, action type, and timestamps. Set up workflows to log page views on every page load and button clicks on key actions. Build an admin analytics page with a data table and summary counts.
Frequently asked questions
Will tracking user sessions use a lot of workload units?
Each SessionLog creation is a database write costing approximately 0.5 WU. For an app with 100 daily active users averaging 5 page views each, that is about 250 WUs per day — manageable on most paid plans.
Can I track anonymous visitors who are not logged in?
Yes, but you cannot use the User field. Instead, generate a random ID stored in a cookie or URL parameter and save it as a text field on the SessionLog.
Should I use this instead of Google Analytics?
Use both. Google Analytics excels at traffic sources, SEO data, and acquisition. Native tracking gives you user-level behavioral data tied to your own database for product decisions.
How do I prevent the SessionLog table from growing too large?
Schedule a recurring backend workflow that deletes or archives SessionLog records older than 90 days. This keeps your database lean and search queries fast.
Can I export the analytics data?
Yes. Go to Data tab → App data → SessionLog and click Export to download all records as CSV for analysis in spreadsheets or BI tools.
Can RapidDev build a custom analytics dashboard for my Bubble app?
Absolutely. RapidDev can design comprehensive analytics dashboards with custom charts, cohort analysis, and automated reporting tailored to your specific business metrics.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation