What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags

View all Tags

Google Analytics - Active Users (Custom Metric)



I'm looking for some examples of how to create a custom metric with the Google Analytics sensor.

Google Analytics Sensor https://www.paessler.com/manuals/prtg/google_analytics_v2_sensor

There are some other KB's that point to the GA Dimensions & Metrics API https://developers.google.com/analytics/devguides/reporting/core/dimsmets

And there is the GA Realtime Reporting API https://developers.google.com/analytics/devguides/reporting/realtime/v3/

The standard values are easy enough to add, i.e. users/sessions etc, but, custom examples are harder to find. Specifically, I'm looking for the following two custom metrics: Active Users on the website Active Users on a specific page

google google-analytics google-api

Created on Feb 19, 2019 9:54:25 PM

8 Replies



I found what I believe to be the metric desired for Active Users. Link: https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get Metric: rt:activeUsers

Though not sure if PRTG works with GA's Realtime Reporting API?

Created on Feb 20, 2019 3:46:36 PM



Tried to see if I could enter the Realtime metric, but, it automatically looks for metrics starting with "ga:"

Received the following warning on the GA sensor added: "Invalid dimension or metric: ga:rt:activeUsers"

Again, not sure PRTG works with GA Realtime Reporting API at present.

Created on Feb 20, 2019 4:03:04 PM



The other possible option is to use the Python Script Advanced Sensor https://www.paessler.com/manuals/prtg/python_script_advanced_sensor

Now to determine if this will generate output in the format PRTG requires.

Created on Feb 20, 2019 4:21:14 PM



Hi there,

I guess "Invalid dimension or metric: ga:rt:activeUsers" is a valid error as there is indeed no dimension or metric with this name as far as I can tell, see here.

Kind regards,


Created on Feb 21, 2019 7:08:01 AM by  Erhard Mikulik [Paessler Support]



Yes that does appear to be a valid error. Though I did not add the "ga:", it was automatically added by PRTG. Which leads me to believe that the sensor only works with the Core API and not the Realtime Reporting API.

I'm looking into creating a python script to pull that data. Will update with any progress.

Created on Feb 22, 2019 5:47:07 PM



Found several independent resources providing examples of how to leverage Python to access the Google Analytics Realtime Reporting API. The following appears to be the most concise. Working through, but, wanted to post so as to not leave ticket "abandoned". Will update with details if/when I get working for reference.


Created on Feb 27, 2019 2:52:09 PM



Circling back, I was able to write the Python script to pull Realtime Reporting API data from Google Analytics ... locally. I found some of the initial challenges were in utilizing the current Google Analytics API's correctly. As a number of the examples I found online referenced deprecated API's etc.

Here are a few of the resources that ultimately provided the most help: Google API Client Libraries - Python https://developers.google.com/api-client-library/python/

OAuth2 Service Account (setting up a Service Account) https://developers.google.com/identity/protocols/OAuth2ServiceAccount

Google Analytics API v3 Explorer https://developers.google.com/apis-explorer/#p/analytics/v3/analytics.data.realtime.get

Here's the script that I've gotten to work (on a locally installed Python):

# Python script to pull Active User count on website from Google Analytics via Realtime Reporting API
from google.oauth2 import service_account
from googleapiclient.discovery import build

API_NAME = 'analytics'
ACCOUNT_EMAIL = '<svc-account>@<project>.iam.gserviceaccount.com' #generated from Google Developer
KEYFILE = './client_secrets.json' #downloaded from Google Developer
ANALYTICS_VIEW_ID = 'ga:<#########>' #gathered from GA account
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
RT_ACTIVE_USERS = 'rt:activeUsers'
RT_DIMENSIONS = 'rt:medium'

credentials = service_account.Credentials.from_service_account_file(KEYFILE, scopes=SCOPES)
service = build(API_NAME, API_VERSION, credentials=credentials)

results = service.data().realtime().get(ids=ANALYTICS_VIEW_ID, metrics=RT_ACTIVE_USERS, dimensions=RT_DIMENSIONS).execute()
totals = results.get('totalsForAllResults')
active_users = int(totals.get("rt:activeUsers"))
print str(active_users)

Next challenge/step - edit script to use json and paepy modules and configure Python on PRTG probe to add Google APIs
Python Sensor Example -> C:\Program Files (x86)\PRTG Network Monitor\Custom Sensor\python\sensor_example.py
Add Google Module -> C:\Program Files (x86)\PRTG Network Monitor\Python34\Lib

Viewing the example python script sensor provided in PRTG install shows:
# -*- coding: utf-8 -*-

import sys
import json
# get CustomSensorResult from paepy package
from paepy.ChannelDefinition import CustomSensorResult

if __name__ == "__main__":
    # interpret first command line parameter as json object
    data = json.loads(sys.argv[1])

    # create sensor result
    result = CustomSensorResult("This sensor is added to " + data['host'])

    # add primary channel
    result.add_channel(channel_name="Percentage", unit="Percent", value=87, is_float=False, primary_channel=True,
                       is_limit_mode=True, limit_min_error=10, limit_max_error=90,
                       limit_error_msg="Percentage too high")
    # add additional channel
    result.add_channel(channel_name="Response Time", unit="TimeResponse", value="4711")
    # print sensor result to std

Created on Mar 19, 2019 6:28:46 PM

Last change on Mar 19, 2019 8:02:37 PM by  Torsten Lindner [Paessler Support]



Great job, KryPRTGadmin. Thank you for sharing this.

Created on Mar 20, 2019 7:55:01 AM by  Erhard Mikulik [Paessler Support]

Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.