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

@meniga/analytics

v6.1.36-alpha.0

Published

A library to track events and send them to analytics services, like meniga, google, or segment

Downloads

639

Readme

@meniga/analytics

This package is used to track events in Meniga products

Getting started


Create a config file called tracking.js in your container app that specifies which tracking services should be enabled.

Example:

export default {
	services: {
		google: {
			enabled: true,
			useAsDefault: true,
			id: "UA-10093770-21",
			debug: false
		},
		meniga: {
			enabled: true,
			useAsDefault: false
		},
		segment: {
			enabled: true,
			id: "",
			useAsDefault: false
		}
	}
};

Not all fields are required for each service, but enabled and useAsDefault should always be present.

enabled means that the service is "turned on" and can be explicitly called when needed.

useAsDefault means that the service is always called during tracking calls, allowing you to call multiple services as default if needed. Note: enabled needs to be true as well.

Tracking an event


To track an event you need to import the analytics actions to your component, like this:

import { actions as trackingActions } from '@meniga/analytics'

and then you use it like this:

  1. Track Screen
dispatch(trackingActions.trackScreen(request, service))

The request param can either be a single string or a JSON object that should look something like this:

{
    type: 'modal' //optional [string] - possible vales: 'page', 'modal', 'tab'. Default value is 'page'.
    category: 'Transactions', //optional [string] - the category of the screen. Useful to group different screens together.
    name: 'Transaction List', //required [string] - the name of the screen to track
}

If you send only a single string to trackScreen() it is used as the name of the screen.

  1. Track Event
dispatch(trackingActions.trackEvent(request, service))

The request param should look something like this:

{
    type: 'Account', //optional [string] (used as trackingType for meniga's /eventtracking service)
    action: 'Account Updated', //required [string] (used as trackingState for meniga's /eventtracking service)
    id: 1, //optional [number] (used as trackingId for meniga's /eventtracking service)
    meta: {}, //optional [json] (used as media for meniga's /eventtracking service)
}

The service param, if specified, should be a string array. Only the services listed will be called, otherwise the 'useAsDefault' services will be called.

Example:

dispatch(trackingActions.trackEvent({
    action: 'Account Updated',
    meta: {
        fields: [
            name: 'Account Type',
            value: 'Current'
        ]
    }
}, ['segment', 'meniga']))

Adding new services


Right now we have a built in support for google analytics, segment.com and the meniga /eventtracking api service. In order to add support for a new service, you need to add code to the identifyUser and trackEvent functions in api.js that deals with calling that service. Then you also might have to add code to the initialize.js file to initialize the connection to the service.

Example:

function callMenigaService () {		
    if(supportedServices.meniga) {
        return Request.post(`${ baseUrl }/eventtracking`, { trackingType, trackingState, trackerId, meta })
    } else {
        return new Promise((resolve) => {
            resolve()
        })
    }
}
function callGoogleService () {
    if(supportedServices.google) {
        return new Promise((resolve, reject) => {
            if (trackingType === 'modal') {
                ReactGA.modalview(trackingState)
            } else if (trackingType === 'event') {
                ReactGA.event(trackingState)
            } else if (trackingType === 'page') {
                ReactGA.pageview(trackingState)
            }
            resolve()
        })
    } else {
        return new Promise((resolve) => {
            resolve()
        })
    }
}
function callSegmentService() {
    if(supportedServices.segment) {
        return new Promise((resolve) => {
            if(trackingType === 'page') {
                analytics.page(trackingState)
            } else {
                analytics.track(trackingState, meta);
            }				

            resolve()
        })
    } else {
        return new Promise((resolve) => {
            resolve()
        })
    }
}

etc.