SMFHacks Analytics for Google
https://www.smfhacks.com/index.php?action=downloads;sa=view;down=263SMFHacks Analytics for GoogleVersion: 1.0.0
Author: vbgamer45 -
https://www.smfhacks.comLicense: MIT
Compatible with: SMF 2.1.x
DescriptionA comprehensive Google Analytics 4 (GA4) integration for Simple Machines Forum. This modification provides deep analytics tracking, server-side event collection via the Measurement Protocol, Google OAuth2 API access, and in-admin reporting - all without modifying any core SMF files.
FeaturesTracking- GA4 tracking code (gtag.js) automatically injected on all forum pages
- Track registered members across devices using their user ID
- Track which theme/style users are using
- Track boards via custom GA4 dimension
- Track topics via custom GA4 dimension
- Track user groups with configurable priority ordering
- Client-side error tracking (JavaScript errors, console errors, failed image loads, unhandled promise rejections)
Event Tracking- User registrations (sign_up event)
- User logins (login event)
- New topic creation (create_content event)
- New reply/post creation (create_content event)
- Personal messages sent (create_content event)
- Attachment downloads tracked server-side via Measurement Protocol (file_download event)
- Paid subscription views, checkout, and purchases tracked as GA4 eCommerce events (view_item_list, begin_checkout, purchase)
- UTM parameters automatically added to links in outgoing forum emails
Google Analytics API Integration- OAuth2 authentication using your own Google Cloud credentials
- Browse and select existing GA4 properties from your Google Analytics accounts
- Create new GA4 properties and data streams directly from the admin panel
- Measurement Protocol API secret auto-generated
- Custom dimensions automatically created in your GA4 property (board_id, topic_id, style_id, user_group_id, user_id, and error tracking dimensions)
In-Admin Reporting- Dashboard - Realtime visitor map showing active users by country (Google GeoChart, auto-refreshes every 30 seconds)
- Charts - Configurable line charts with date range, dimension (OS, browser, country, city, page, device, language, board, topic), metric (page views, sessions, active users, events, new users), and minimum value filter
- Heat Map - Weekly activity heatmap (hour of day x day of week) with configurable metric, weeks of data, and end date
- Errors - Client-side error report showing error type, message, page URL, location, line number, and occurrence count
Requirements- SMF 2.1.x
- PHP 7.0+ with cURL extension enabled
- A Google Analytics 4 property (created automatically or select an existing one)
- Google Cloud OAuth2 credentials (Client ID and Client Secret) - see setup instructions below
Installation1. Install via SMF Package Manager (Admin > Packages > Install a Package)
2. After installation you will be redirected to the settings page
Setup InstructionsStep 1: Create Google Cloud OAuth Credentials1. Go to
Google Cloud Console - Credentials2. Create a project (or select an existing one)
3. Enable the following APIs:
- Google Analytics Admin API
- Google Analytics Data API
4. Go to Credentials > Create Credentials > OAuth 2.0 Client ID
5. Application type: Web application
6. Add your forum URL as an Authorized redirect URI:
https://yourforum.com/index.php?action=smfhacks_analytics;sa=oauth_callback7. Copy the Client ID and Client Secret
Step 2: Configure the Modification1. Go to Admin > Configuration > Analytics for Google > Settings
2. Enter your OAuth Client ID and Client Secret
3. Click Save
4. Click "Link Google Account" and authorize access
5. Select an existing GA4 property or create a new one
6. The Measurement ID and API Secret will be auto-populated
7. Custom dimensions are automatically created in your GA4 property
8. Configure which tracking features and events you want enabled
9. Set user group priority order if desired
Step 3: Enable Enhanced Measurement (Recommended)In your Google Analytics account:
1. Go to Admin > Property > Data Streams
2. Click your web data stream
3. Enable Enhanced Measurement for automatic tracking of scrolling, outbound clicks, site search, video engagement, and file downloads
How It WorksClient-side tracking: The gtag.js script is injected on every page via SMF's integrate_load_theme hook. Custom dimensions (board, topic, style, user group) are set based on the current page context.
Event queue: Forum actions (login, registration, topic/post creation, PMs) are queued in the PHP session and fired as gtag() calls on the user's next page load.
Server-side tracking: Attachment downloads and paid subscription purchases are tracked via the GA4 Measurement Protocol directly from PHP, since these actions don't render a page.
Reporting: Admin report pages fetch data from the Google Analytics Data API via an AJAX proxy endpoint, keeping page loads fast.
100% hook-based: This modification uses 14 SMF integration hooks and does not modify any core SMF files.
Hooks Used- integrate_actions
- integrate_admin_areas
- integrate_load_theme
- integrate_pre_javascript_output
- integrate_pre_css_output
- integrate_login
- integrate_register_after
- integrate_create_topic
- integrate_create_post
- integrate_personal_message_after
- integrate_download_request
- integrate_outgoing_email
- integrate_exit
- integrate_daily_maintenance
UninstallationUninstall via SMF Package Manager. All hooks are automatically removed, all files are deleted, and all settings are cleaned from the database. No traces are left behind.
SupportFor support, bug reports, and feature requests visit
https://www.smfhacks.com
Changelog1.0.0 - Initial release
- GA4 tracking code injection with custom dimensions
- Google OAuth2 integration with property selection and creation
- Forum event tracking (login, registration, topics, posts, PMs, downloads)
- Client-side error tracking
- Paid subscription eCommerce tracking
- Email UTM tagging
- In-admin reporting (dashboard, charts, heat map, errors)