Skip to content

Conversation

@subodhr258
Copy link
Collaborator

@subodhr258 subodhr258 commented Nov 13, 2025

Issue - [Feature] Add PostHog support for GoDAM (rtCamp/godam-core#465)
https://github.com/rtCamp/godam-core/issues/625

This pull request introduces PostHog analytics tracking across the GoDAM plugin, allowing internal event tracking for product improvement. It adds configuration and settings for enabling/disabling PostHog, integrates the PostHog provider into all major React entrypoints, and ensures the analytics client is initialized with server-provided configuration. The changes are grouped below by theme.

Analytics Integration

  • Added PostHog tracking to all major React entrypoints by wrapping app components in PostHogProvider and initializing the client with configuration from the server (posthogConfig). This affects pages such as the dashboard, analytics, media library, tools, help, video editor, godam, and what's new. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Created pages/utils/posthog.js to initialize the PostHog client with configuration from window.posthogConfig, ensuring tracking is only enabled if configured.

Backend Configuration and Script Localization

  • Added a new method get_posthog_config() in class-pages.php to provide PostHog public keys, host, and enabled status, and localized this configuration to all relevant admin scripts so the frontend can initialize analytics correctly. [1] [2] [3] [4] [5] [6] [7] [8]

Settings Management

  • Added enable_posthog_tracking to the plugin's default settings and ensured it is properly sanitized and managed in the REST API and Redux slice, allowing users to enable or disable analytics from the settings UI. [1] [2] [3]
  • Added a toggle control for "Enable PostHog Analytics" in the general settings panel of the React UI, allowing users to opt in or out of analytics tracking.

Dependencies

  • Added @posthog/react and posthog-js to package.json as new dependencies required for analytics integration. [1] [2]

Screenshots

Screenshot 2025-12-30 at 7 11 39 PM Screenshot 2025-12-30 at 9 18 07 PM Screenshot 2025-12-30 at 4 03 29 PM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates PostHog analytics tracking throughout the GoDAM plugin to enable internal event tracking for product improvement. The implementation adds PostHog configuration on the backend, wraps all major React entrypoints with the PostHog provider, and provides user-configurable settings to enable or disable tracking.

  • Added PostHog React provider integration to all major admin pages (dashboard, analytics, media library, tools, help, video editor, godam, and what's new)
  • Implemented backend configuration method to provide PostHog API keys and settings to the frontend via script localization
  • Added user-facing toggle control in general settings to enable/disable PostHog analytics tracking

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pages/utils/posthog.js New utility to initialize PostHog client with server-provided configuration
pages/whats-new/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/video-editor/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/tools/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/media-library/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/help/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/godam/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/godam/redux/slice/media-settings.js Added enable_posthog_tracking to Redux initial state with default value true
pages/godam/components/tabs/GeneralSettings/GeneralSettings.jsx Added toggle control for enabling/disabling PostHog analytics in settings UI
pages/dashboard/index.js Wrapped app component in PostHogProvider for analytics tracking
pages/analytics/index.js Wrapped app component in PostHogProvider for analytics tracking
package.json Added @posthog/react and posthog-js dependencies for analytics integration
package-lock.json Lockfile updates for new PostHog dependencies and their transitive dependencies
inc/classes/rest-api/class-settings.php Added enable_posthog_tracking to default settings and sanitization logic
inc/classes/class-pages.php Added get_posthog_config() method and localized PostHog configuration to all admin scripts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@subodhr258 subodhr258 removed the request for review from KMchaudhary November 14, 2025 10:24
@subodhr258
Copy link
Collaborator Author

Need to apply settings and notice to client in a proper way, needs discussion.

@github-actions
Copy link

github-actions bot commented Dec 30, 2025

🔍 WordPress Plugin Check Report

❌ Status: Failed

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
29 12 17

❌ Errors (12)

📁 inc/classes/wpforms/wpforms-field-godam-record-frontend.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/wpforms/wpforms-field-godam-record-entry-view.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/wpforms/wpforms-field-godam-record-entry-edit.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/class-rewrite.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/class-elementor-widgets.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/everest-forms/everest-forms-field-godam-record-frontend.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/assets/class-ima-assets.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/assets/class-jetpack-form-assets.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/class-video-preview.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/lifter-lms/class-lifter-lms.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/fluentforms/class-form-submit.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;
📁 inc/classes/class-video-engagement.php (1 error)
📍 Line 🔖 Check 💬 Message
0 missing_direct_file_access_protection PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;

⚠️ Warnings (17)

📁 composer.json (1 warning)
📍 Line 🔖 Check 💬 Message
0 missing_composer_json_file The "/vendor" directory using composer exists, but "composer.json" file is missing.
📁 readme.txt (2 warnings)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM".
0 trademarked_term The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name.
📁 inc/classes/media-library/class-media-folder-utils.php (1 warning)
📍 Line 🔖 Check 💬 Message
91 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $where_clause used in $wpdb->get_var($wpdb->prepare(\n\t\t\t\t"\n\t\t\tSELECT COUNT(DISTINCT p.ID)\n\t\t\tFROM {$wpdb->posts} p\n\t\t\tINNER JOIN {$wpdb->term_relationships} tr ON p.ID = tr.object_id\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id\n\t\t\tWHERE {$where_clause}\n\t\t",\n\t\t\t\t$query_params\n\t\t\t))\n$where_clause assigned unsafely at line 82:\n $where_clause .= ' AND p.post_mime_type LIKE %s'\n$query_params[] used without escaping.\n$mime_type used without escaping.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (6 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?p=1 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?page_id=2 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?attachment_id=6 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?godam-video=demo-godam-video-post (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (6 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?p=1 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?page_id=2 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?attachment_id=6 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/?godam-video=demo-godam-video-post (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants