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

docpad-plugin-analytics

v2.1.1

Published

Retrieves google analytics data from your analytics account so it can be displayed within a docpad application

Downloads

3

Readme

Google Analytics Data Plugin for DocPad

Build Status NPM version NPM downloads

Retrieves Google Analytics data using serverside authentication via the embed api. Google returns analytic data in the form of a JSON object which can be used to produce tables, charts and reports. The plugin does not create these reports - just retrieves the data (which is really the hard part). Once you have the data it is simple enough to use something like Chart.js to create nice visual charts. The charts example shows how to do this. The data returned from the plugin is an abbreviated version of that returned from google.

{

    "totalResults": 20,
    "columnHeaders": [
        {
            "name": "ga:pagePath",
            "columnType": "DIMENSION",
            "dataType": "STRING"
        },
        {
            "name": "ga:uniquePageviews",
            "columnType": "METRIC",
            "dataType": "INTEGER"
        }
    ],
    "totalsForAllResults": {
        "ga:uniquePageviews": "27845"
    },
    "rows": [
        [
            "/",
            "6500"
        ],
        [
            "/news",
            "21345"
        ]
    
    ]
}

The advantage of this approach that you don't need to give users access to your analytics account and the users don't need to log in to google to access the data. This makes a lot more sense for an admin style page that shows analytic data. Of course, you will probably want to protect this admin page with some sort of login for the website. So you will probably want to use this plugin in conjunction with an authentication plugin such as docpad-plugin-authentication.

The plugin relies on downloading from Google what they call a "JSON key". This is a json file containing all the necessary credentials for making calls to the embed API. All details can be found at: https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

Once you have the "JSON key" you need to place it in the root of your DocPad application. The plugin will load it from there. By default the plugin expects it to be named "credentials.json".

In docpad.coffee file configure the google analytics id for your site.

    plugins:
        analytics:
            qryId: 'ga:123456789'

Each analytics query is identified by an endPoint. The endPoint parameter is appended to the base dataURL, by default, /analytics/data. So to retrieve the uniquePageviews query your application needs to make a call to /analytics/data/uniquePageviews.

    $.getJSON('/analytics/data/uniquePageviews',function(data){
        $('#results pre').html(JSON.stringify(data,null,4));
    });

The endpoints for the default, built in queries are:

  • "30daysPageviews"
    'metrics': 'ga:uniquePageviews'
    'dimensions': 'ga:pageTitle'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'
  • "uniquePageviews"
    alias for "30daysPageviews"
  • "7daysPageviews"
    'metrics': 'ga:uniquePageviews'
    'dimensions': 'ga:pageTitle'
    'start-date': '7daysAgo'
    'end-date': 'yesterday'
  • "yesterdayPageviews"
    'metrics': 'ga:uniquePageviews'
    'dimensions': 'ga:pageTitle'
    'start-date': 'yesterday'
    'end-date': 'yesterday'
  • "60daySessions"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:date'
    'start-date': '60daysAgo'
    'end-date': 'yesterday'
  • "30dayCountry"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:country,ga:countryIsoCode'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'
  • "7daysCountry"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:country,ga:countryIsoCode'
    'start-date': '7daysAgo'
    'end-date': 'yesterday'
  • "yesterdayCountry"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:country,ga:countryIsoCode'
    'start-date': 'yesterday'
    'end-date': 'yesterday'
  • "browserAndOS"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:browser,ga:browserVersion,ga:operatingSystem,ga:operatingSystemVersion'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'
  • "timeOnSite"
    'metrics': 'ga:sessions,ga:sessionDuration'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'
  • "trafficSources"
    'metrics': 'ga:sessions,ga:pageviews,ga:sessionDuration,ga:exits'
    'dimensions': 'ga:source,ga:medium'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'
  • "keywords"
    'metrics': 'ga:sessions'
    'dimensions': 'ga:keyword'
    'start-date': '30daysAgo'
    'end-date': 'yesterday'

To build and test queries use google's query explorer