Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gosquared

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gosquared

GoSquared for your Node.JS application

  • 0.3.1
  • npm
  • Socket score

Version published
Weekly downloads
73
increased by82.5%
Maintainers
4
Weekly downloads
 
Created
Source

node-gosquared

This lightweight, zero-dependency module allows you to integrate the GoSquared API into your Node.JS app with ease.

Commonly, you'll use this module to retrieve analytics data collected by GoSquared, but it can also be used to manage accounts, store events, and record transactions for GoSquared Ecommerce.

It can also be used in a backend app to proxy requests from a frontend app to the GoSquared API so you don't publicly expose your API Key.

Installation

npm install --save gosquared

Usage

var GoSquared = require('gosquared');
var gosquared = new GoSquared(opts);
Options
  • api_key: API key from your account. Required for API functions, not required for tracking functions.
  • site_token: Token for the registered site you're working with. Required.
  • requestTimeout: Maximum time in ms an API request can be pending. Default 2000ms
  • debugLevel: One of 'NONE', TRACE', 'NOTICE', 'WARNING', 'ALL'. Default 'WARNING'

API

Methods mirror the structure of the GoSquared API:

gosquared[namespace][version][function]

Consult the API Docs for available namespaces, versions, and functions.

Example: We want to get the total number of visitors online on the site right now. For this, we need to use the concurrents function under the v3 version of the now namespace:

var GoSquared = require('gosquared');

var gosquared = new GoSquared({
  api_key: 'demo',
  site_token: 'GSN-181546-E'
});

gosquared.now.v3.concurrents(function(e,data) {
  if (e) return console.log(e);
  console.log(data)
});

All functions listed in the API documentation are methods you can call on the gosquared object. The documentation also demonstrates the response data you can expect to get back.

Recording data with this module

The module can also be used to send data to GoSquared.

Transactions

To record a transaction:

var transactionID = 123456789
var t = gosquared.createTransaction(transationID);

// Make sure each item has a name
t.addItem({
	name: 'Beer',
	price: 3.50,
	quantity: 1,
	category: 'Alcoholic Drinks'
});

// You can also add multiple items at once
t.addItems([
{
	name: 'More Beer',
	price: 4.99,
	quantity: 2,
	category: 'Alcoholic Drinks'
},
{
	name: 'Limoncello',
	price: 17.99,
	quantity: 1,
	category: 'Liquor'
}
]);

// Send off to GoSquared
t.record(function(){
	// Done
});

GoSquared automatically calculates the total revenue and quantity for each transaction by summing these values of each item. If you would like to override the total transaction revenue and quantity, you can do the following:

// Override revenue and quantity amounts before t.record()

var customRevenue = 10;
var customQuantity = 5
t.revenue = customRevenue;
t.quantity = customQuantity;

t.record();
Events

Send events to GoSquared:

gosquared.event('Test Event', {
		its: true,
		'you can': 'store',
		any: 'event',
		properties: 'You Like'
	},
	function(e, res){
		if(e) return console.log(e);
		console.log(res);
	}
);

Run tests

Install test dependencies using npm install then:

make test

Optionally, you can run the tests with a site token and API key of your choice:

SITE_TOKEN=<your token> API_KEY=<your api key> make test

Keywords

FAQs

Package last updated on 22 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc