New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aicore/core-analytics-client-lib

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aicore/core-analytics-client-lib

Analytics client library for https://github.com/aicore/Core-Analytics-Server

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
671
decreased by-8.83%
Maintainers
3
Weekly downloads
 
Created
Source

Core Analytics Client Lib - JS

The Javascript client library to be used from browser/nodejs to raise analytics events for Core-Analytics-Server.

Code Guardian

<app> build verification

Sonar code quality check Security rating vulnerabilities Code Coverage Code Bugs Reliability Rating Maintainability Rating Lines of Code Technical debt

Usage

Load the Library

Embed the script in your HTML file :

<script src="https://unpkg.com/@aicore/core-analytics-client-lib/src/analytics.js"></script>

This will create a global analytics variable which can be used to access the analytics APIs.

Initialize the analytics session.

Call analytics.initSession() after loading the library. It takes the following parameters:

  • accountID: Your analytics account id as configured in the server or core.ai analytics
  • appName: The app name to log the events against. Eg: "phoenixCode"
  • postIntervalSeconds (Optional): This defines the interval between sending analytics events to the server. Default is 10 minutes
  • granularitySec (Optional): The smallest time period under which the events can be distinguished. Multiple events happening during this time period is aggregated to a count. The default granularity is 3 Seconds, which means that any events that happen within 3 seconds cannot be distinguished in ordering.
  • analyticsURL (Optional): Provide your own analytics server address if you self-hosted the server
  • debug (Optional): set to true if you want to see detailed debug logs.

usageExample

// Init with default values.
analytics.initSession("accountID", "appName");

// Example for custom initSession where the analytics aggregated data 
// is posted to custom server https://localhost:3000 every 600 secs
// with a granularity(resolution) of 5 seconds.
analytics.initSession("accountID", "appName", "https://localhost:3000", 600, 5);

// To initSession in debug mode set debug arg in init to true:
analytics.initSession("accountID", "appName", "https://localhost:3000", 600, 5, true);

Raising analytics events

Once initSession is called, we can now start logging analytics events by calling analytics.event API. The API registers an analytics event. The events will be aggregated and send to the analytics server periodically.

// analyticsEvent(eventType, eventCategory, subCategory, eventCount, eventValue);

// Eg: event without counts and values
analytics.event("platform", "os", "linux");

// Eg: event with count, here it logs that html file is opened 100 times
analytics.event("file", "opened", "html", 100);

// Eg: event with count and value, here it logs that the startup time is 250 milliseconds. 
// Note that the value is unitless from analytics perspective. unit is deduced from subCategory name
analytics.event("platform", "performance", "startupTimeMs", 1, 250);

// Eg: event with fractional value.
analytics.event("platform", "CPU", "utilization", 1, .45);
// Eg. Here we register that the system has 8 cores with each core having 2300MHz frequency.
analytics.event("platform", "CPU", "coreCountsAndFrequencyMhz", 8, 2300);

API parameters

  • eventType - A string, required
  • eventCategory - A string, required
  • subCategory - A string, required
  • eventCount (Optional) : A non-negative number indicating the number of times the event (or an event with a particular value if a value is specified) happened. defaults to 1.
  • eventValue (Optional) : A number value associated with the event. defaults to 0

Contribute to core-analytics-client-lib

Building

Since this is a pure JS template project, build command just runs test with coverage.

> npm install   # do this only once.

# Before raising a pull request, run release script and add the generated
# minified files in dist folder to commits .
# WARNING!!!: If the minified files are not checkedin git push will fail. 
> npm run release

Linting

To lint the files in the project, run the following command:

> npm run lint

To Automatically fix lint errors:

> npm run lint:fix

Testing

To run tests, open the file test/unit-test.html in the browser.

Publishing packages to NPM

To publish a package to npm, raise a pull request against npm branch.

Dependency updates

We use Rennovate for dependency updates: https://blog.logrocket.com/renovate-dependency-updates-on-steroids/

Code Guardian

Several automated workflows that check code integrity are integrated into this template. These include:

  1. GitHub actions that runs build/test/coverage flows when a contributor raises a pull request
  2. Sonar cloud integration using .sonarcloud.properties
    1. In sonar cloud, enable Automatic analysis from Administration Analysis Method for the first time image

IDE setup

SonarLint is currently available as a free plugin for jetbrains, eclipse, vscode and visual studio IDEs. Use sonarLint plugin for webstorm or any of the available IDEs from this link before raising a pull request: https://www.sonarlint.org/ .

SonarLint static code analysis checker is not yet available as a Brackets extension.

Internals

Testing framework: Mocha , assertion style: chai

See https://mochajs.org/#getting-started on how to write tests Use chai for BDD style assertions (expect, should etc..). See move here: https://www.chaijs.com/guide/styles/#expect

Keywords

FAQs

Package last updated on 20 May 2022

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