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

@marcdiethelm/nuxtjs-countly

v0.6.0

Published

Nuxt plugin providing Countly web SDK tracker

Downloads

12

Readme

@marcdiethelm/nuxtjs-countly

A Nuxt.js plugin providing Countly's web SDK / analytics / tracker. Github, API, docs

The plugin lazy loads the Countly tracker by adding a script element as last child in html body with async=true. It then checks for script load every 500ms for 30s, until the script is loaded or it times out. After successful script load window.Countly is injected into Vue components and Nuxt context as $countly.

Based on nuxtjs-countly by gweill, a published npm module without public source code. If you are the original author please contact me.

Installation and Config

npm install --save @marcdiethelm/nuxtjs-countly

In nuxt.config.js...

  • add this line to the modules array:
'@marcdiethelm/nuxtjs-countly'
  • and add this configuration data somewhere below:
/*
 ** Countly tracker configuration (@marcdiethelm/nuxtjs-countly)
 */
countly: {
	// Required, the URL of your Countly server
	url: process.env.MYAPP_COUNTLY_URL || 'http://mycountly.lan',
	
	// Required, copy from server's management > apps page
	app_key: process.env.MYAPP_COUNTLY_APP_KEY || 'b0ccb5ea1fd4000000000000448ed463d87d334f',
	
	// For self-hosting... use original .js or .min.js (minified)
	// Default: https://cdn.jsdelivr.net/npm/countly-sdk-web@latest/lib/countly.min.js
	trackerSrc: process.env.MYAPP_COUNTLY_TRACKER_SRC || 'http://mycountly.lan/sdk/web/countly.min.js',
	
	// Automatic tracking, if not array this defaults to ['track_sessions', 'track_pageview', 'track_links']
	trackers: null,
	
	// Append a <noscript> tag with tracking pixel <img> to <body>, default: true
	noScript: true,
	
	// Log Countly debug info to console, default: false
	debug: process.env.NODE_ENV !== 'production'
}

Programmatic usage

Countly is available as this.$countly in Vue.js components and also in context provided by Nuxt.js. (No import is needed.) It is typically used as

this.$countly.q.push()

Consult the Countly web SDK API documentation for further info on using the $countly object.

Examples

Note the function this.onCountlyLoad called on tracker script load, which accepts callbacks.

// ./examples/component.vue

asyncData: function(context) {
	let countly = context.app.$countly
},

created: function() {
	// only in browser
	if (this.$countly) {
		this.$countly.q.push([
			'add_event',
			{
				key: 'page-created'
			}
		])
	}
},

mounted: function() {
	this.$countly.q.push([
		'add_event',
		{
			key: 'page-mounted'
		}
	])

	this.onCountlyLoad(() => {
		this.$countly.q.push([
			'add_event',
			{
				key: 'countly-loaded'
			}
		])
	})
}

This plugin provides a $track helper method, which performs some input checking and pushes to the queue:

this.$track('add_event', {
	key: 'email-signup-success',
	segmentation: { email: this.email }
})

this.$track('log_error', { 
	email: this.email,
	detail: err.message
})

Troubleshooting

  • CORS errors in Firefox despite correct HTTP headers:

    Are you running an ad blocker? Blocked connection by an identified tracker script will show as a CORS error in Firefox.