Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
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.
npm install --save gosquared
var GoSquared = require('gosquared');
var gosquared = new GoSquared(opts);
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.
The module can also be used to send data to GoSquared.
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();
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);
}
);
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
FAQs
GoSquared for your Node.JS application
The npm package gosquared receives a total of 64 weekly downloads. As such, gosquared popularity was classified as not popular.
We found that gosquared demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.