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

mozaik-ext-analytics

v0.3.2

Published

Google Analytics widgets for Mozaïk dashboard

Downloads

5

Readme

mozaik-ext-analytics

Module provides some Google Analytics widgets for Mozaïk dashboard.

preview-page-views

Table of contents

Setup

Follow the steps to install and configure widget into dashboard

Dependencies

  • Install modules from npmjs:

    npm install -S mozaik-ext-analytics
  • Register client api by adding to dashboard app.js:

    import analytics from 'mozaik-ext-analytics/client';
    mozaik.bus.registerApi('analytics', analytics;
  • Register widgets by adding to dashboard src/App.jsx:

    import analytics from 'mozaik-ext-analytics';
    mozaik.addBatch('analytics', analytics);
  • (Re)build the dashboard:

    npm run build-assets
  • Configure widgets (see Widgets -section)

  • Start dashboard: node app.js

Google Analytics

  • Login to Developers Console: https://console.developers.google.com/ (register Google account if you don't already have one)

  • Create new project dashboard (or similar)

  • Enable following Analytics API from permissions

  • Create Service account under Credentials: Create new Client ID -> Service account -> Download mozaik-ext-analytics.p12 file

  • Convert .p12 file into .pem format with command:

    openssl pkcs12 -in mozaik-ext-analytics*.p12 -nodes -nocerts > mozaik-ext-analytics.pem

    The password for .p12 file is notasecret

  • Authorize service user to acces analytics property in question by adding the service email address via User Management

  • Configure service auth details in dashboard root file: .env (or as environment variables):

    GOOGLE_SERVICE_EMAIL=generated-by-google-console@developer.gserviceaccount.com
    # one of the following:
    GOOGLE_SERVICE_KEY=abcdef123456...
    GOOGLE_SERVICE_KEYPATH=mozaik-ext-analytics.pem

    Alternatively use export command to set environment variables.

  • Run command line app to retrieve ids (or see them from analytics - see references):

    node node_modules/mozaik-ext-analytics/cli.js

    OR

Widgets

Set api and wiget configuration values in dashboard config.js. See followup section for details.

module.exports = {
  // Configure api
  api: {
    analytics: {
      // NOTE: Either key or key path needs to be provided
      googleServiceEmail: process.env.GOOGLE_SERVICE_EMAIL,
      googleServiceKey: process.env.GOOGLE_SERVICE_KEY
      googleServiceKeypath: process.env.GOOGLE_SERVICE_KEYPATH
    },
    // Other services ...
  },

  // Set widgets
  dashboards: [
    columns: 2,
    rows: 2,
    // See next sections for details
    widgets: [
      {
        type: 'analytics.page_views',
        id: '123123123',
        startDate: '30daysAgo',
        columns: 2, rows: 2,
        x: 0, y: 0
      }
    ]
  ]
}

Finally, start the dashboard with command:

node app.js

Widget: analytics.page_views

Show the number of page views as a timeseries

preview-page-views

parameters

key | required | description --------------|----------|--------------- id | yes | Id of the analytics data to show. See setup steps or analytics view for more info. Example: 1231234321 startDate | no | Starting date info used in Analytics. Example/default: '30daysAgo' endDate | no | End date info used in Analytics. Example/default: 'yesterday' title | no | Textual title to show. Example: 'My website'.

usage

{
  type: 'analytics.page_views',
  id: '123123123',
  startDate: '30daysAgo',
  columns: 2, rows: 1,
  x: 1, y: 0
}

Widget: analytics.top_pages

Show list of pages, in order of most visits within given time range.

preview-top-pages

parameters

key | required | description --------------|----------|--------------- id | yes | Id of the analytics data to show. See setup steps or analytics view for more info. Example: 1231234321 dimensions | no | The dimensions and metrics explorer lists and describes all the dimensions and metrics available through the Core Reporting API. Use this reference API : Example: ga:pageTitle startDate | no | Starting date info used in Analytics. Example/default: '30daysAgo' endDate | no | End date info used in Analytics. Example/default: 'yesterday' title | no | Textual title to show. Example: 'My website'.

usage

{
  type: 'analytics.top_pages',
  id: '123123123',
  startDate: '30daysAgo',
  columns: 2, rows: 1,
  x: 1, y: 0
}

License

Distributed under the MIT license

Credit

The module is backed by SC5