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 🙏

© 2026 – Pkg Stats / Ryan Hefner

trackly-sdk

v0.2.6

Published

SDK leve de analytics para tracking de eventos no browser

Readme

Trackly SDK

SDK leve de analytics para tracking de eventos no browser.

🚀 Instalação

npm install trackly-sdk
# ou
yarn add trackly-sdk
# ou
pnpm add trackly-sdk

📦 Uso

Inicialização

import { Analytics } from "trackly-sdk";

const analytics = new Analytics({
  apiUrl: "https://api.seuapp.com/events",
  batchSize: 10, // opcional: eventos por batch (padrão: 10)
  flushInterval: 5000, // opcional: intervalo de envio em ms (padrão: 5000)
  maxRetries: 3, // opcional: tentativas em caso de erro (padrão: 3)
  debug: false, // opcional: ativar logs de debug (padrão: false)
});

Tracking de Eventos

// Evento customizado
analytics.track("button_clicked", {
  button: "signup",
  page: "homepage",
  variant: "primary",
});

// Pageview (automático por padrão, mas pode chamar manualmente)
analytics.pageview({
  category: "blog",
  author: "John Doe",
});

// Identificar usuário
analytics.identify("user_123", {
  email: "[email protected]",
  name: "João Silva",
  plan: "premium",
});

Exemplos Práticos

E-commerce

// Produto visualizado
analytics.track("product_viewed", {
  product_id: "SKU-123",
  name: "Tênis Running",
  price: 299.9,
  category: "Esportes",
});

// Item adicionado ao carrinho
analytics.track("cart_add", {
  product_id: "SKU-123",
  quantity: 1,
  price: 299.9,
});

// Compra finalizada
analytics.track("purchase", {
  order_id: "ORD-456",
  total: 299.9,
  currency: "BRL",
  items: 1,
});

SaaS

// Cadastro
analytics.identify("user_789", {
  email: "[email protected]",
  company: "Startup Inc",
  plan: "trial",
});

// Feature utilizada
analytics.track("feature_used", {
  feature: "export_data",
  format: "csv",
  rows: 1500,
});

// Upgrade de plano
analytics.track("plan_upgraded", {
  from: "trial",
  to: "premium",
  mrr: 99.0,
});

🔧 API

Analytics

Métodos

  • track(eventName: string, properties?: EventProperties)
    Rastreia um evento customizado

  • pageview(properties?: EventProperties)
    Rastreia visualização de página

  • identify(userId: string, traits?: UserTraits)
    Identifica o usuário

  • flush(): Promise<void>
    Força envio imediato dos eventos na fila

  • getUserId(): string | undefined
    Retorna o userId atual

  • getAnonymousId(): string
    Retorna o ID anônimo (persistido no localStorage)

  • shutdown(): void
    Para o SDK e limpa recursos

🎯 Características

  • Leve: Sem dependências externas
  • Type-safe: Totalmente tipado com TypeScript
  • Batch automático: Agrupa eventos para reduzir requests
  • Retry automático: Reenvio em caso de falha (exponential backoff)
  • sendBeacon: Garante envio antes de sair da página
  • Contexto automático: Captura URL, referrer, user agent, etc
  • Anonymous ID: Tracking persistente antes da identificação

🏗️ Build

pnpm run build

Gera:

  • dist/index.js (CommonJS)
  • dist/index.esm.js (ES Modules)
  • dist/index.d.ts (TypeScript definitions)

📊 Formato dos Eventos

Todos os eventos enviados seguem esta estrutura:

{
  type: 'track' | 'page' | 'identify',
  timestamp: 1234567890,
  event?: 'button_clicked',           // apenas para type='track'
  properties?: { /* dados custom */ },
  userId?: 'user_123',
  anonymousId: 'anon_xxx',
  traits?: { /* dados do usuário */ }, // apenas para type='identify'
  context: {
    page: {
      url: 'https://...',
      path: '/about',
      title: 'Sobre',
      referrer: 'https://...'
    },
    userAgent: '...',
    locale: 'pt-BR',
    timezone: 'America/Sao_Paulo',
    screen: { width: 1920, height: 1080 }
  }
}

📝 Licença

MIT