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

@palta-brain/analytics

v0.7.0

Published

This SDK helps to organize events in batches and to send batches to PaltaBrain API endpoint.

Downloads

56

Readme

Table of Contents

  • About The Project
  • Getting Started
    • Installation
    • Static config
    • Generation
    • Local environment
  • Usage

About The Project

This SDK helps to organize events in batches and to send batches to PaltaBrain API endpoint.

Getting Started

Installation

  1. Get url and key from paltabrain team

  2. Install NPM package

npm install @palta-brain/analytics

!Important. Tested only with npm.

Static config

When launching the analytics and logging files generator, the path parameter is mandatory. This parameter defines the directory where there will be no files named analytics.js and proto.js. This is necessary to avoid overwriting data in these files.

After the corresponding files are generated, all further work will be carried out with the analytics.js file, which is the main entry point.

Generation

Run next command

node node_modules/@palta-brain/analytics/dist/generator.cjs --url {url} --key {key} --path {path} [--shorten true --platforms Web,MobileWeb --dev true, --port {port}]

| Param | Description | Default value | Required | |---|---|---|---| | url | This link is also your login. It determines the address to which the events will be sent | - | true | | key | A key is the equivalent of a password | - | true | | path | The path to the generated analytics.js and proto.js file | - | true | | shorten | If true, all non-web events will be stripped. All descriptions will be stripped from data validation. | false | false | | platfroms | Activates platform filter, skipping events that are not marked for platforms. You can include several platfroms separating with comma without spaces. In terms of filtering, takes precedence over shorten. | - | false | | dev | This enables the operating mode for the local environment. This mode sends a request to http://localhost:8010/proxy. See chapter Local environment for more information | false | false | | port | Parameter that overrides the port. Used for local environment only | 8010 | false |

Local environment

For local environment you have to install proxy lib and start generation in dev mode. For proxy lib I recommend https://www.npmjs.com/package/local-cors-proxy

npm install -g local-cors-proxy

After it you have to start proxy

lcp --proxyUrl {url}

You can ovveride port if you need

lcp --proxyUrl {url} --port {port}

If you run generation with dev mode it shoulde use localhost url like main url and proxy will be redirect it to needed url.

node node_modules/@palta-brain/analytics/dist/generator.cjs --url {url} --key {key} --dev true

Usage

  1. Import lib:
import analytics from "{path}/analytics";
  1. Initialize SDK use init function. !Important. If you do not run the init function, nothing will work
analytics.init({
  logger?: (error: string) => void;
  defaultContext?: boolean;
  storageMode?: StorageMode;
  showLogs?: boolean;
});

Storage mode you can found in

analytics.config.storage;

| Param | Description | Default value | Required | |---|---|---|---| | logger | A logger is a function that will be called every time an error occurs. By default it is an empty function. But you can throw in console.log or, for example, sentry. The only parameter is a string that stores the error text | (error: string) => {} | false | | storageMode | StorageMode allows you to select the storage location where the data batches will be stored. There are two main parameters IN_MEMORY - we will save data in RAM only, IN_DB - we will use browser storage, currently LocalStorage, in the future IndexedDB | analytics.config.storage.IN_DB | false | | defaultContext | Used to set the default context settings | true | false | | showLogs | If set to true, the event name and its parameters will be logged to the console (not recommended for production) | false | false |

defaultContext

context.setApplication({ appPlatform: "Web" });
context.setOs({
  osName: parserResults.os.name,
  osVersion: parserResults.os.version,
});
context.setDevice({
  deviceBrand: parserResults.device.vendor,
  deviceCarrier: "",
  deviceModel: parserResults.device.model,
});
  1. Set context properties.

Contex are the parameter that will be stamped on all the event submissions. Some parameters we fill in by default (you can disable this function). You can fill in, overwrite, or reset any parameters you enter.

The functions to set the relevant parts of the context are in the context object.

Each function takes a context object with typed parameters. Remember that only the parameters you passed in will be replaced

Example:

import analytics from "{path}/analytics";

analytics.context.setUser({ userId: 'UserId'});
...
  1. Push event

Inside the events object you can find a list of all the categories, each of which will contain the corresponding functions for the required event. In order to send an event, you only need to call the function.

Note that each function may or may not accept the parameter object. If the function has no parameters, no object will be required. Otherwise, remember that parameters of this object are typed. They are typed not only at autocomplete and hint level, but also typing exists in runtime.

// Event without properties

  analytics.events.Logical.TestCase()?.track();

// Event with event properties

  analytics.events.Logical.EdgeCase({
    propString: 'String',
  })?.track();
...
  1. Additional types

We can use additional types that do not exist in JS. If you see such types in the hint, you can find them in the types object.

new analytics.types.Decimal(1);
new analytics.types.Long(11);
  1. Enum

Enum may be used for some parameters. If you come across such a parameter, you can find all the enums you need in the enum object/

analytics.enums.ResultEnum.resultError;
analytics.enums.ResultEnum.resultSuccess;