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

mpjql-cli

v1.0.0

Published

Commandline tool for writing and running jql queries against mixpanel

Downloads

3

Readme

MixPanel JQL Command Line Interface

Installing this package will give you a new command line tool called jql. This enables you to write JQL using modern javascript techniques, including:

  • Split common code into modules
  • Modern ES2015 Syntax
  • String Template Literals
  • etc.

Example

Move commonly used functions to their own file...

// date.js
export const dateToString = e => {
  return new Date(Number(e)).toISOString().substr(0, 10)
}

...and then import them when needed.

// example.js
import { dateToString } from './date'
const today = new Date()
const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
function main() {
  return Events({
    from_date: dateToString(yesterday),
    to_date: dateToString(today)
  })
    .groupByUser((user, events) => (user || 0) + events.length)
    .map(user => `${user.key[0]}: ${user.value}`)
}

The jql command line tool uses Rollup.js, Babel and Uglify under the hood to compile the script before sending it to MixPanel.

Installation

npm install -g mpjql-cli

Visit MixPanel and copy your secret from your user settings page.

export MPSECRET=<secret>

Set this either locally in your terminal, or in ~/.profile.

Basic Usage

Create a JQL query, then run it as follows:

jql query myQuery.js

Results will be streamed to the terminal. Redirect to a file or other commands.

jql query myQuery.js > output.json

Advanced Usage

JQ

jq is an amazing tool for highlighting JSON results, or doing additional filtering of your results.

jql query myQuery.js | jq

It also has the capability to produce CSV with selected fields on the fly from returned JSON.

jql query myQuery.js | jq -r '.results[] | [.field1, .field2] | @csv' > output.csv

Passing settings to your scripts

Settings can be passed on the command line to configure a script. This can be extremely useful when dealing with scripts that can be configured to find info about a specific user, or date range.

Settings are passed on the command line:

jql query myQuery.js --setting='foo=bar' --setting='baz=boo,bop'

The special variable __SETTINGS__ will be replaced with an object containing all of your settings.

// myQuery.js
const settings = __SETTINGS__
function main() { /* ... */ }

will effectively become...

// myQuery.js
const settings = {
  'foo':'bar',
  'baz':['boo','bop']
}
function main() { /* ... */ }

CLI commands

query

Compile a script and execute it against your MixPanel account. Prints the resulting JSON into the STDOUT.

jql query myQuery.js

show-code

You can debug how a script is being compiled by replacing query with show-code. This prints the compiled javascript to the terminal for inspection.

jql show-code myQuery.js

encode

If you are integrating your scripts with another platform (such as Klipfolio) where you need the script URI encoded.

jql encode myQuery.js

Contributing

See CONTRIBUTING.md for more information on how you can help make this tool better.