# How to implement user session tracking for analytics in Bubble.io: Step-by-Step 

- Tool: Bubble
- Difficulty: Beginner
- Time required: 20-25 min
- Compatibility: All Bubble plans
- Last updated: March 2026

## TL;DR

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.

## Before you start

- 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

### 1. 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.

### 2. 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.

### 3. 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.

### 4. 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.

### 5. 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.

### 6. 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 code example

File: `Workflow summary`

```text
USER SESSION TRACKING — WORKFLOW SUMMARY
=========================================

DATA TYPE: SessionLog
  Fields:
  - user (User)
  - page_name (text)
  - action_type (text) — page_view, button_click, form_submit
  - action_detail (text) — specific element name
  - session_start (date)
  - session_end (date)

WORKFLOW 1: Track Page View
  Event: Page is loaded
  Condition: Current User is logged in
  Action 1: Create a new thing → SessionLog
    - user = Current User
    - page_name = "Dashboard" (or Current page name)
    - action_type = "page_view"
    - session_start = Current date/time
  Action 2: Set state of index → current_session = Result of step 1

WORKFLOW 2: Track Button Click
  Event: When [Button] is clicked
  Action 1: Create a new thing → SessionLog
    - user = Current User
    - page_name = Current page name
    - action_type = "button_click"
    - action_detail = "Add to Cart Button"
    - session_start = Current date/time

WORKFLOW 3: Record Session End
  Event: Do when condition is true (Current User is logged out)
  Action: Make changes to index's current_session
    - session_end = Current date/time

ADMIN DASHBOARD:
  Repeating Group: Do a search for SessionLog, sorted by Created Date desc
  Summary: SessionLog search (action_type = page_view) :count
  Chart: daily counts grouped by Created Date

PRIVACY RULES:
  SessionLog:
  - Admin users: full access
  - All users: create only
```

## Common mistakes

- **Tracking every single user action and creating too many database records** — Each SessionLog record costs workload units and can slow down your app as the database grows Fix: Track only key actions — page views and important button clicks. Use a backend workflow to purge old records monthly.
- **Not adding privacy rules to the SessionLog data type** — Without privacy rules, any user could potentially access other users' activity data via the API Fix: Add a privacy rule that restricts find-in-searches and view-all-fields to admin users only
- **Forgetting to handle logged-out users** — If a user is not logged in, the user field will be empty and you cannot attribute the activity Fix: 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

## 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.

---

Source: https://www.rapidevelopers.com/bubble-tutorial/implement-user-session-tracking-analytics-bubble
© RapidDev — https://www.rapidevelopers.com/bubble-tutorial/implement-user-session-tracking-analytics-bubble
