symmetrics

1.2.0 • Public • Published

Symmetrics

Know your website, not your users. It’s time to make the move away from Google Analytics. With Symmetrics, you own the data. Enjoy powerful visualization tools, full developer freedom, and happy users: Privacy is our top priority.

Start your free 7-day trial on https://getsymmetrics.com.

npm i symmetrics

Browser usage

Loading the signal

Retrieve your symmetricsId from the Symmetrics website. Then import the script in your browser package:

import symmetrics from 'symmetrics';
symmetrics('tmMJXR6YvKK0iWnAItxRcQVubNYXzXDATQn3ae');

You can add an options object as the second argument, like this:

symmetrics('tmMJXR6YvKK0iWnAItxRcQVubNYXzXDATQn3ae', {
    automaticallySendPageViewEvent: false
});

Read more about signal options here.

Sending custom events

Ensure you’ve included and ran the above script before sending custom events.

import {signal} from 'symmetrics';
signal('event', 'order_complete');

Read more about sending custom events here.

Server or non-browser usage

Retrieve your Symmetrics user ID and an authentication key from the Symmetrics website. Then import the package:

import client from 'symmetrics/client';
const symmetrics = client('ac76c1a2-79ff-4a5f-88fe-9b543182acad', 'JfJ0V8jiNEevhI5TDECja5Lw0wYVh0B48e1u');

The first argument is your Symmetrics user ID, the second is the authentication key. The third is an optional options object.

Options

timezoneOffset (optional)

When using timestamps in queries, ensure the observer (client or server) timezone offset in relation to GMT is also provided. For GMT+2, the timezoneOffset would be +7200000, eg. two hours ahead.

const symmetrics = client(userId, authenticationKey, {
    timezoneOffset: 1000 * 60 * 60 * 2
});

You can set the current timezone offset like this:

const symmetrics = client(userId, authenticationKey, {
    timezoneOffset: new Date().getTimezoneOffset() * 60 * 1000 * -1
});

This setting can be overridden per query.

query: Performing queries

Write queries using JsonQl to extract the data you need.

import client from 'symmetrics/client';
const symmetrics = client(userId, authenticationKey);
 
// Using promises
symmetrics.query('unique event')
    .then((results) => console.log(results))
    .catch((error) => console.error(error));
 
// Using async
try {
    const results = await symmetrics.query('unique event');
    console.log(results);
} catch (error) {
    console.error(error);
}

Query options

A second argument queryOptions can be passed to the query function as an object.

timezoneOffset (optional)

When using timestamps in queries, ensure the observer (client or server) timezone offset in relation to GMT is also provided. For GMT+2, the timezoneOffset would be +7200000, eg. two hours ahead.

symmetrics.query('where timestamp > 1601052331102', {
    timezoneOffset: 1000 * 60 * 60 * 2
});

You can add the current timezone offset like this:

symmetrics.query('where timestamp > 1601052331102', {
    timezoneOffset: new Date().getTimezoneOffset() * 60 * 1000 * -1
});

This setting overrides the top level client options timezoneOffset.

signal: Sending custom events

Use the built-in signal function to send custom events.

import client from 'symmetrics/client';
const symmetrics = client(userId, authenticationKey);
 
// Using promises
symmetrics.signal('event', 'user_login')
    .then((results) => console.log(results))
    .catch((error) => console.error(error));
 
// Using async
try {
    const results = await symmetrics.signal('event', 'server_restart');
    console.log(results);
} catch (error) {
    console.error(error);
}

Read more about sending custom events here.

Apps

apps.tweets: Retrieving tweets about your websites

import client from 'symmetrics/client';
const symmetrics = client(userId, authenticationKey);
 
// Using promises
symmetrics.apps.tweets()
    .then((results) => console.log(results))
    .catch((error) => console.error(error));
 
// Using async
try {
    const results = await symmetrics.apps.tweets();
    console.log(results);
} catch (error) {
    console.error(error);
}

You can also provide an options object with startTimestamp and/or endTimestamp to filter the output.

symmetrics.apps.tweets({
    startTimestamp: 1600103109877,
    endTimestamp: 1600103109879
});

Readme

Keywords

none

Package Sidebar

Install

npm i symmetrics

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

9.44 kB

Total Files

4

Last publish

Collaborators

  • symmetrics