Back to Main Site

PolyCMS Google Analytics Plugin for RISE CRM

Last updated on Nov 22, 2026 11:14 AM 11:14 AM 5,530.70 ms

The bundled Google Analytics plugin connects your PolyCMS for RISE CRM frontend with Google Analytics 4 (GA4) tracking while maintaining a built-in local post view counter stored directly in your CRM database. It automatically excludes logged-in RISE staff and administrators from analytics noise and adds a Top Performing Posts widget to the PolyCMS Dashboard for quick content insights.

Key Capabilities

  • Google Analytics 4 (GA4) Integration: Automatically injects the asynchronous gtag.js snippet into your public frontend <head> section via the polycms_head hook whenever a Measurement ID is configured.
  • Staff Traffic Exclusion: Automatically skips both GA4 script injection and local view counting for logged-in RISE staff and admin sessions so internal content reviews do not inflate visitor metrics.
  • Local Post View Counter: Tracks unique per-session views for every published post in a dedicated database table ({prefix}polycms_post_views), preventing repeated page refreshes from skewing counts.
  • Dashboard Widget: Adds a Top Performing Posts widget directly to PolyCMS > Dashboard, displaying the top 5 published articles ranked by views with direct edit links.

Activation

  1. In your RISE CRM admin panel, navigate to PolyCMS > Plugins.
  2. Locate Google Analytics in the plugin list and click Activate.
  3. Upon activation, PolyCMS automatically creates the {prefix}polycms_post_views InnoDB table and adds a Google Analytics shortcut to the PolyCMS sidebar menu.
  4. Click Settings on the plugin card or open PolyCMS > Google Analytics (/polycms/plugins/settings/google-analytics).

Configuring GA4 Tracking

To connect your website to Google Analytics 4, retrieve your Measurement ID (format G-XXXXXXXXXX):

  1. Sign in to Google Analytics.
  2. Go to Admin > Data Streams > Web and select your website stream.
  3. Copy the Measurement ID (G-XXXXXXXXXX).
  4. In RISE CRM, paste the ID into the Google Analytics Measurement ID field on the Google Analytics settings screen.
  5. Click Save Settings.

The Status panel on the right side updates immediately from Not Configured to Active, confirming the active Measurement ID.

How Tracking Works on the Frontend

When a public visitor loads any frontend page on your PolyCMS site, the plugin runs two independent tracking layers:

Layer Hook / Mechanism Behavior
GA4 Global Site Tag polycms_head (priority 5) Outputs the googletagmanager.com/gtag/js script tag and gtag('config', 'G-XXXXXXXXXX') inside <head> for public visitors only.
Local Post View Counter polycms_single_post_view Increments views and updates last_viewed_at in {prefix}polycms_post_views once per visitor session (ga_viewed_{post_id}).

Because the GA4 script loads in the <head> element with the async attribute, page rendering stays fast while capturing page views accurately before users navigate away.

Using the Top Performing Posts Dashboard Widget

Once the plugin is active, open PolyCMS > Dashboard (/polycms/dashboard) to view the Top Performing Posts widget. The widget automatically queries published posts joined with {prefix}polycms_post_views and displays:

  • The top 5 published posts ordered from highest to lowest view count.
  • Direct links to open each article in the post editor (/polycms/posts/edit/{id}).
  • Formatted local view counts that work even if you have not yet entered a GA4 Measurement ID.

Theme Developer Helper Functions

If you are building or customizing a PolyCMS theme, you can also display local view counts or popular post lists in your templates using the plugin's helper functions:

<?php
// Display total local views for a single post
if (function_exists('ga_plugin_get_views')) {
    echo number_format(ga_plugin_get_views($post->id)) . ' views';
}

// Fetch the top 10 published posts by local views
if (function_exists('ga_plugin_get_top_posts')) {
    $top_posts = ga_plugin_get_top_posts(10);
}

Verifying Your Setup

Because logged-in RISE CRM staff visits are intentionally excluded from tracking, always test using a logged-out browser session:

  1. Open an incognito or private browser window (not signed into RISE CRM).
  2. Visit a published post on your PolyCMS frontend.
  3. Open your browser's View Page Source and search for your G-XXXXXXXXXX Measurement ID inside the <head> block.
  4. Check Reports > Realtime in Google Analytics to confirm your active visit appears.
  5. Return to PolyCMS > Dashboard in your admin session and verify that the visited post now appears in the Top Performing Posts widget.

Related Documentation