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

usergeek-ic-js

v1.0.5

Published

Usergeek Javascript SDK for Internet Computer

Downloads

543

Readme

Usergeek-IC-JS

Usergeek JavaScript IC SDK for Internet Computer can be installed as an npm package.

Installation

NPM

Install the npm package and embed Usergeek JavaScript IC SDK into your project.

npm install usergeek-ic-js

Import Usergeek JavaScript IC SDK into your code.

import {Usergeek} from "usergeek-ic-js"
//or
const {Usergeek} = require("usergeek-ic-js")

Usage

Initialization

Project API key is needed to initialise Usergeek JavaScript IC SDK.

It can be found in your project settings at https://fbbjb-oyaaa-aaaah-qaojq-cai.raw.ic0.app/.

Usergeek.init({
    apiKey: "<API_KEY>",
    host: "https://ic0.app" | undefined //used on environments other than IC main network
})

Setting Principal

Principal should be set after initialization with the setPrincipal method. It could be either from AuthClient.authClient.login() method onSuccess callback, or from any wallet (Plug, Stoic...). Only non-anonymous Principal can be used for session tracking.

//identity got from AuthClient.authClient.login()
const principal: Principal = identity.getPrincipal()
Usergeek.setPrincipal(principal)

Log Out

If a user logs out you will need to:

Usergeek.setPrincipal(undefined)

Session tracking

This method will send session related event to Usergeek analytics canister. It should be called after non-anonymous principal is set.

Be sure to call setPrincipal + trackSession every time user auto-logins.

Usergeek.trackSession()

Sending Events

You can track an event by calling trackEvent method with the event name:

Usergeek.trackEvent("PostCreated")

Full example

//somewhere in the very start of an app (e.g. index.tsx)
Usergeek.init({
    apiKey: "<API_KEY>" //change <API_KEY> with your api key
})

//...

//after user sign-in (lets say Principal is available in "userPrincipal" variable)
Usergeek.setPrincipal(userPrincipal)
Usergeek.trackSession()

//...

//somewhere in your app
Usergeek.trackEvent("PostCreated")

//...

//after user sign-out
Usergeek.setPrincipal(undefined) //or Usergeek.setPrincipal(Principal.anonymous())

Constraints

  • Currently, Usergeek provides metrics only for registered users (non-anonymous Principals).
  • Sessions and custom events are temporarily tracked once per user per day (to reduce the number of update calls and cycles burned).
  • Please note that babel plugin @babel/plugin-transform-exponentiation-operator" transforms the exponentiation assignment operator to Math.pow() function which does not support BigInt.One of the solutions could be to reduce number of supported browsers in package.json:
"browserslist": {
  "production": [
    "last 2 chrome version",
    "last 2 firefox version",
    "last 2 safari version",
    "last 2 edge version"
  ],
}

Usergeek on environments other than IC main network

If you’re testing on an environment other than IC main network (e.g. local DFX replica) you need to add additional parameter host to the Usergeek.init function passing your service public asset canister URL e.g. “https://ic0.app”.

In order not to mix users from development environment with users from production environment we suggest separating development (DEV) and production (PROD) environments by creating additional project in Usergeek portal.

Final initialization in the code would look like this:

const USERGEEK_PROJECT_API_KEY_PROD = "ABCD"
const USERGEEK_PROJECT_API_KEY_DEV = "EFGH"
const SERVICE_PUBLIC_URL = "https://ic0.app"

if (process.env.NODE_ENV === "development") {
    Usergeek.init({apiKey: USERGEEK_PROJECT_API_KEY_DEV, host: SERVICE_PUBLIC_URL})
} else {
    Usergeek.init({apiKey: USERGEEK_PROJECT_API_KEY_PROD})
}

If you are integrating Usergeek into Web2.0 website (e.g. hosted on AWS) - you should pass Dfinity base domain as a host (https://ic0.app/).

Community

If you have any questions or suggestions please join our Discord server.

License

Usergeek-IC-JS is distributed under the terms and conditions of the MIT license.