npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@automattic/jetpack-analytics

v0.1.29

Published

Jetpack Analytics Package

Downloads

160

Readme

Analytics

This module includes functionality for interacting with analytics packages.

Turn on debugging in the JavaScript developer console to view calls being made with the analytics module:

In Calypso: localStorage.setItem('debug', 'calypso:analytics'); In Jetpack wp-admin: localStorage.setItem('debug', 'dops:analytics');

Which analytics tool should I use?

Page Views (analytics.pageView.record) should be used to record all page views (when the main content body completely changes). This will automatically record the pageview to both Google Analytics and Tracks.

Google Analytics should be used to record all events the user performs on a page that do not trigger a page view (this will allow us to determine bounce rate on pages).

We are using GA to monitor user flows through the user interface of Calypso in order learn where they succeed and fail, as well as determine usage of different sections. Please do not ship anything that does not have GA tracking in place, otherwise we will create big gaps in our understanding.

Automatticians may refer to internal documentation for more information about MC/Tracks.

Usage

// require the module
var analytics = require( 'analytics' );

PageView Wrapper

analytics#pageView#record( pageURL, pageTitle )

Record a pageview:

analytics.pageView.record( '/posts/draft', 'Posts > Drafts' );

Google Analytics API

analytics#ga#recordPageView( pageURL, pageTitle )

Record a virtual pageview:

analytics.ga.recordPageView( '/posts/draft', 'Posts > Drafts' );

Note: Unless you have a strong reason to directly record a pageview to GA, you should use analytics.pageView.record instead

analytics#ga#recordEvent( eventCategory, eventAction [, optionLabel, optionValue ] )

Record an event:

analytics.ga.recordEvent( 'Reader', 'Clicked Like' );
analytics.ga.recordEvent( 'Reader', 'Loaded Next Page', 'page', 2 );

For more information and examples about how and when to provide the optional optionLabel and optionValue parameters, refer to the Google Analytics Event Tracking documentation.

Tracks API

analytics#tracks#recordEvent( eventName, eventProperties )

Record an event with optional properties:

analytics.tracks.recordEvent( 'calypso_checkout_coupon_apply', {
	'coupon_code': 'abc123'
} );

MC API

analytics#mc#bumpStat( group, name )

Bump a single WP.com stat.

analytics.mc.bumpStat( 'newdash_visits', 'sites' );

analytics#mc#bumpStat( obj )

Bump multiple WP.com stats:

analytics.mc.bumpStat( {
	'stat_name1': 'stat_value1',
	'statname2': 'stat_value2'
} );

Google Analytics Naming Conventions

For page view tracking, you should never pass a dynamic URL, or anything including a specific domain e.g. (/posts/example.wordpress.com). Always pass a placeholder in these instances (/posts/:site). If you do not do this, we cannot accurately track views for a specific page. Titles should always use a > to break up the hierarchy of the page title. Examples are Posts > My > Drafts, Reader > Following > Edit, Sharing > Connections.

Events should be categorized by the section they are in. Examples are Posts, Pages, Reader, Sharing. Event actions should be written in readable form, and action centric. Good examples are Clicked Save Button, Clicked Like, Activated Theme.

Tracks Naming Conventions

Event names should be prefixed by calypso_ to make it easy to easy to identify when analyzing the data with our various analytics tools.

Each token in the event and property names should be separated by an underscore (_), not spaces or dashes.

In order to keep similar events grouped together when output in an alphabetized list (as is typical with ananlytics tools), put the verb at the end of the event name:

  • calypso_cart_product_add
  • calypso_cart_product_remove

If we had instead used calypso_add_cart_product and calypso_remove_cart_product for example, then they'd likely be separated in a list of all the event names.

Finally, for consistency, the verb at the end should not be in the form add, remove, view, click, etc and not adds, added, adding, etc.

With the exception of separating tokens with underscores, these rules do not apply to property names. coupon_code is perfectly fine.