PHPackages                             automattic/jetpack-stats - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. automattic/jetpack-stats

ActiveJetpack-library[Utility &amp; Helpers](/categories/utility)

automattic/jetpack-stats
========================

Collect valuable traffic stats and insights.

v0.18.1(2mo ago)522.1k↓31.8%15GPL-2.0-or-laterPHPPHP &gt;=7.2CI passing

Since Oct 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/Automattic/jetpack-stats)[ Packagist](https://packagist.org/packages/automattic/jetpack-stats)[ RSS](/packages/automattic-jetpack-stats/feed)WikiDiscussions trunk Synced 1mo ago

READMEChangelogDependencies (14)Versions (70)Used By (5)

Stats
=====

[](#stats)

Collect valuable traffic stats and insights.

How to consume Stats package
----------------------------

[](#how-to-consume-stats-package)

### Install the right packages

[](#install-the-right-packages)

First, let's make sure that the `automattic/jetpack-stats` package is set up in your composer.json file:

At minimum you need three things. One is the `automattic/jetpack-autoloader` package, which will ensure that you're not colliding with any other plugins on the site that may be including the same packages. Two, of course, is the `automattic/jetpack-stats` package. Third is our `automattic/jetpack-config` package that will be your tool for initializing the packages.

### Initialize the package

[](#initialize-the-package)

Second, we must initialize ("configure") the `jetpack-stats` package within your plugin, and provide the information about it.

This is where the `jetpack-config` and `jetpack-autoload` packages come into play. Do this, and you're ready to start consuming the Jetpack connection!

```
use Automattic\Jetpack\Config;

require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload_packages.php';

function jpcs_load_plugin() {

	// Here we enable the Jetpack packages.
	$config = new Config();
	$config->ensure( 'stats' );
}

add_action( 'plugins_loaded', 'jpcs_load_plugin', 1 );
```

Tracking Pixel
--------------

[](#tracking-pixel)

Stats Package uses a tracking pixel to send information to WordPress.com.

This is done by enqueueing a JavaScript file in the footer of the site `https://stats.wp.com/e-202103.js` (the number changes every week but the file remains the same). That JavaScript file, in turn, inserts a tracking pixel to the end of the page. For example: `https://pixel.wp.com/g.gif?lots_of_parameters_here`When that tracking pixel is loaded by the browser, it effectively sends information to WordPress.com about what needs to be logged on.

### Parameters tracked

[](#parameters-tracked)

#### Default parameters

[](#default-parameters)

The default parameters being tracked are built with the `Automattic\Jetpack\Stats\TrackingPixel::build_view_data` function.

- **v**: (internal) Used to distinguish self-hosted sites from the ones hosted on WordPress.com. Enum: `ext, wpcom`
- **blog**: The blog ID of the site
- **post**: The id of the post for the site. 0 if it is not a post.
- **tz**: The GMT offset
- **srv**: THe URL of the server.

#### How to extend default parameters

[](#how-to-extend-default-parameters)

There is a filter that can be used to track more parameters. `stats_array`

```
add_filter( 'stats_array', 'filter_stats_array_add_custom_stat' );

/**
 * Add custom stat to the stats tracking data.
 *
 * @param  param array $kvs The stats array in key values.
 * @return array
 */
function filter_stats_array_add_custom_stat( $kvs ) {
	$kvs['custom_stat'] = 'my_custom_stat'
	return $kvs;
```

WPCOM Stats API
---------------

[](#wpcom-stats-api)

The stats package provides an easy to use API that Fetches data from WPCOM.

### Available Methods

[](#available-methods)

Inside `Automattic\Jetpack\Stats\WPCOM_Stats` class you can find the following methods. All of them internally rely on the following method `Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_blog`.

- `get_stats`: Get site's stats
- `get_stats_summary`: Get site's summarized views, visitors, likes and comments.
- `get_top_posts`: Get site's top posts and pages by views.
- `get_video_details`: Get the details of a single video.
- `get_referrers`: Get site's referrers.
- `get_clicks`: Get site's outbound clicks.
- `get_tags`: Get site's views by tags and categories.
- `get_top_authors`: Get site's top authors.
- `get_top_comments`: Get site's top comment authors and most-commented posts.
- `get_video_plays`: Get site's video plays.
- `get_file_downloads`: Get site's file downloads.
- `get_post_views`: Get a post's views.
- `get_views_by_country`: Get site's views by country.
- `get_followers`: Get site's followers.
- `get_comment_followers`: Get site's comment followers.
- `get_publicize_followers`: Get site's publicize follower counts.
- `get_search_terms`: Get search terms used to find the site.
- `get_total_post_views`: Get the total number of views for each post.
- `get_visits`: Get the number of visits for the site.

Using this package in your WordPress plugin
-------------------------------------------

[](#using-this-package-in-your-wordpress-plugin)

If you plan on using this package in your WordPress plugin, we would recommend that you use [Jetpack Autoloader](https://packagist.org/packages/automattic/jetpack-autoloader) as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.

Security
--------

[](#security)

Need to report a security vulnerability? Go to  or directly to our security bug bounty site .

License
-------

[](#license)

stats is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community34

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Total

68

Last Release

81d ago

PHP version history (2 changes)v0.7.0PHP &gt;=7.0

v0.14.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c5869ecbb8e0eac7e8b8e0f3cf7bdd8d5fcdc4abc10a72281872c53f8639d44?d=identicon)[automattic](/maintainers/automattic)

![](https://www.gravatar.com/avatar/11609890f6e7a840715f4cfc9622d77ea64b7dfc024df5643fbf8471a18c00f3?d=identicon)[kraft](/maintainers/kraft)

![](https://www.gravatar.com/avatar/5326730499ec14e274f51b9bcc39db6aac0fb38b33849715aae0e2587a2b93df?d=identicon)[jeherve](/maintainers/jeherve)

![](https://www.gravatar.com/avatar/6e220e167e341c28b1aa10bf0bb0374999068329f8683d3187ee3cf6749b8837?d=identicon)[dereksmart](/maintainers/dereksmart)

![](https://www.gravatar.com/avatar/62dfbfcb6fed563989595d0f4e0a0de6c05e5fc7a37dbcf7f3a93de4d6e75793?d=identicon)[bindlegirl](/maintainers/bindlegirl)

---

Top Contributors

[![anomiex](https://avatars.githubusercontent.com/u/1030580?v=4)](https://github.com/anomiex "anomiex (153 commits)")[![tbradsha](https://avatars.githubusercontent.com/u/32492176?v=4)](https://github.com/tbradsha "tbradsha (97 commits)")[![jeherve](https://avatars.githubusercontent.com/u/426388?v=4)](https://github.com/jeherve "jeherve (41 commits)")[![zinigor](https://avatars.githubusercontent.com/u/374293?v=4)](https://github.com/zinigor "zinigor (37 commits)")[![sergeymitr](https://avatars.githubusercontent.com/u/1341249?v=4)](https://github.com/sergeymitr "sergeymitr (37 commits)")[![bindlegirl](https://avatars.githubusercontent.com/u/1242807?v=4)](https://github.com/bindlegirl "bindlegirl (32 commits)")[![gmjuhasz](https://avatars.githubusercontent.com/u/36671565?v=4)](https://github.com/gmjuhasz "gmjuhasz (23 commits)")[![manzoorwanijk](https://avatars.githubusercontent.com/u/18226415?v=4)](https://github.com/manzoorwanijk "manzoorwanijk (20 commits)")[![kraftbj](https://avatars.githubusercontent.com/u/88897?v=4)](https://github.com/kraftbj "kraftbj (19 commits)")[![samiff](https://avatars.githubusercontent.com/u/15803018?v=4)](https://github.com/samiff "samiff (18 commits)")[![kangzj](https://avatars.githubusercontent.com/u/1425433?v=4)](https://github.com/kangzj "kangzj (13 commits)")[![coder-karen](https://avatars.githubusercontent.com/u/16754605?v=4)](https://github.com/coder-karen "coder-karen (10 commits)")[![dilirity](https://avatars.githubusercontent.com/u/11799079?v=4)](https://github.com/dilirity "dilirity (10 commits)")[![ice9js](https://avatars.githubusercontent.com/u/8056203?v=4)](https://github.com/ice9js "ice9js (10 commits)")[![nateweller](https://avatars.githubusercontent.com/u/10933065?v=4)](https://github.com/nateweller "nateweller (8 commits)")[![sdixon194](https://avatars.githubusercontent.com/u/33553323?v=4)](https://github.com/sdixon194 "sdixon194 (8 commits)")[![darssen](https://avatars.githubusercontent.com/u/13239096?v=4)](https://github.com/darssen "darssen (7 commits)")[![chihsuan](https://avatars.githubusercontent.com/u/4344253?v=4)](https://github.com/chihsuan "chihsuan (6 commits)")[![haqadn](https://avatars.githubusercontent.com/u/3737780?v=4)](https://github.com/haqadn "haqadn (5 commits)")[![zaerl](https://avatars.githubusercontent.com/u/167611?v=4)](https://github.com/zaerl "zaerl (4 commits)")

### Embed Badge

![Health badge](/badges/automattic-jetpack-stats/health.svg)

```
[![Health](https://phpackages.com/badges/automattic-jetpack-stats/health.svg)](https://phpackages.com/packages/automattic-jetpack-stats)
```

###  Alternatives

[automattic/jetpack

Jetpack supercharges your self‑hosted WordPress site with the awesome cloud power of WordPress.com

3621.9k](/packages/automattic-jetpack)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
