From ce7465da8f66bea9c6d702dd70de9c8e5bf572bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Canek=20Pel=C3=A1ez=20Vald=C3=A9s?= Date: Wed, 13 Oct 2021 20:50:38 -0500 Subject: [PATCH] Explain how to use the GAPageStats class. --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0ddf4b..876fd2f 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,27 @@ Google Analytics Page Stats =========================== Google Analytics Page Stats is a [WordPress](https://wordpress.org/) plugin to -access Google Analytics for singular pages in a WordPress installation. +access Google Analytics for pages in a WordPress installation. You need to set up the [necessary tracking for Google Analytics](https://support.google.com/analytics/answer/1008015). Also, you need to [enable the Google Analytics API and create a service account and a JSON -key](https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php). +key](https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php) +for the plugin to use. -After activating the plugin, configur the View ID and the JSON key, and the -stats will appear at the bottom of each singular page in your WordPress -installation when you access it as administrator. +After activating the plugin, configure the View ID and the JSON key, and (if you +enable to show by default) the stats will appear at the bottom of each singular +page in your WordPress installation when you access it as administrator. + +You can disble this, and insert your own PHP code in your theme or widget to +retrieve the page stats and show them as you whish. + +``` +require_once(GA_PAGE_STATS__PLUGIN_DIR . 'class.ga-page-stats.php'); +$r = GAPageStats::getPageStats($_SERVER['REQUEST_URI']); +$spv = number_format($r[0]); +$su = number_format($r[1]); +``` + +At the moment, the plugin retrieves the PageViews (`ga:pageView`) and Users +(`ga:users`) stats for a tracked path. -- GitLab