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

gtm-event

v0.1.2

Published

GTM event helper for node

Downloads

28

Readme

#gtm-event

A Google Tag Manager package for node. It is a simple wrapper for the dataLayer for sending events and virtual pageview tracking to Google Analytics. It does this by assuming a lot of the event variables and trigger event names in GTM. Please see the GTM Setup section below.

This package is useful for setting up simple tracking while keeping your code DRY. It could also work as a recipe for those who are not that familiar with GTM.

Installation

npm install gtm-event

Note

Since v0.1.1 the GTM.Event is called GTM.event to please some linters.

Usage

// Require the package
var GTM = require('gtm-event');

// Or for Meteor
import GTM, {event, virtualPageview} from 'gtm-event';

// Track event
GTM.event('category'(req), 'action'(req), 'label'(opt), value(opt);

// Virtual pageview tracking
GTM.virtualPageview('/my/virtual/path');

The fn(x)´s will return true or false, based on their validity.

GTM Setup

This setup is based on my own preferences, but will hopefully make sense.

First, start by making 5 variables, of the type Data Layer Variable, with the following names and Data Layer Variable names: eventCategory, eventAction, eventLabel, eventValue and eventPage. This will make the different parameters available to us.

Then create a trigger with the name gtm-event and type of Custom Event. It should fire on the event name gtm-event. Make one more trigger, with the names set to gtm-virtualpageview.

Next we´ll configure the actual event tracking tag; Create a tag with the name of gtm-event, and make it an universal analytics type. Input your tracking ID, and select the track type as Event. Insert the eventCategory, eventAction, eventLabel, eventValue variables in the respective fields under Event Tracking Parameters. Click continue, and make it fire on the trigger gtm-event. Then Save the tag.

Make one more tag, and name it gtm-virtualpageview, also as an universal analytics type. The track type will be Pageview for this one, and under More settingsFields to set enter page under field name and insert the eventPage variable in the Value field. Go ahead and make it fire on the gtm-virtualpageview trigger.

Publish the changes to GTM, and your Google Analytics account should be reporting events and virtual pageviews.

####Running tests npm run test