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

springload-analytics.js

v2.0.1

Published

Google analytics event tracking module with support for both classic and universal analytics code.

Downloads

107

Readme

Analytics.js

Google analytics event tracking module with support for both classic and universal analytics code.

Requirements

Requires the async version of the Google Analytics to be loaded in the page. See the tracking code quickstart for more infomation: https://developers.google.com/analytics/devguides/collection/gajs/

Install

npm install --save springload-analytics.js
# or
bower install springload-analytics.js
# or
git clone https://github.com/springload/Analytics.js analytics

Basic setup

Just add a data-analytics attribute to a container containing links you want to track. Every link in that container will be tracked using the default category (uri), default action (click), default label (href), and default value (undefined).

<div data-analytics>
  <ul>
    <li><a href='/'>Home</a></li>
    <li><a href='/about-us/'>About us</a></li>
    <li><a href='/contact-us/'>Contact us</a></li>
  </ul>
</div>

Initialise GA once the document is ready.

jQuery example:

$(document).ready(function() {
    GA.init();
});

Vanilla ES6 example:

import GA from 'springload-analytics.js';

GA.init();

Override default options

You can override default options by passing an object to the init method. JQuery example below

$(document).ready(function() {

    var options = {
        default_category: "Calculator",
        default_action: "Interaction",
        default_separator: ":",
        default_trackable_attribute: "aly",
        default_trackable_event: "mouseenter",
        default_trackable_element: "span",
        default_label_is_text_content: true
        categories: {
            buttons: "Buttons"
        },
        actions: {
            slide_left: "Slide left"
        }
    };

    GA.init(options);

});

Custom tracking

For more targeted tracking you can specify a category, action or value by populating the data-analytics attribute with pipe separated values.

E.g. Use custom category, custom action, custom label and a custom value

<a data-analytics='Top navigation|Link click|Homepage link|1' href='/'>Home</a>

E.g. Use custom label only

<a data-analytics='||Homepage link' href='/'>Home</a>

E.g. Use custom action only

<a data-analytics='|Slide Next' href='#'>Next</a>

E.g. Use custom value only

<a data-analytics='|||1' href='/'>Home</a>

E.g. Use custom category and custom label only

<a data-analytics='UI Elements||Show data' href='#'>Show</a>

E.g. Use custom category and custom value only

<a data-analytics='UI Elements|||1' href='#'>Show</a>

E.g. Custom track a group of elements with custom category and action

<div data-analytics='Top navigation|Link click'>
  <ul>
    <li><a href='/'>Home</a></li>
    <li><a href='/about-us/'>About us</a></li>
    <li><a href='/contact-us/'>Contact us</a></li>
  </ul>
</div>

Tracking dynamically

You can track within a JavaScript file by calling the track method:

GA.track(label, category, action); // Specify a label, category and action.
GA.track(label); // Specify only a label - will use default category and action.
GA.track(label, category, action, value); // Specify a label, category, action and value.

Setup additional trackable elements on the fly

You can set up additional/alternative trackable elements on the fly by calling setupTrackables

    /**
     * Setup additional trackable elements on the fly after initialisation
     * @param trackable_attribute data attribute
     * @param trackable_event event type. e.g. mouseenter
     * @param trackable_element - e.g. span
     * @param label_attribute - where the default label is ready from. e.g. data-label
     * @param label_is_text_content - whether the node's text content is used as label
     */
    GA.setupTrackables("analytics", "mouseenter", "span", "data-label");

The markup for this example would be

<div data-analytics>
    <span data-label='Viewed on hover'>Read more</span>
</div>