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

tma-tracker-sdk

v1.0.0

Published

Client SDK for TMA Tracker - tracking Telegram Mini Apps analytics

Downloads

89

Readme

@tma-tracker/client

Client SDK for TMA Tracker - Track user acquisition and payments in Telegram Mini Apps with UTM parameters.

🚀 Installation

npm install @tma-tracker/client

📖 Quick Start

1. Initialize SDK

import TMATracks from '@tma-tracker/client'

// Initialize on app start
TMATracks.init({
  apiKey: 'your-api-key',
  apiEndpoint: 'https://your-tracker-server.com',
  debug: true // Enable console logs
})

2. Track Payments

// Track when user makes a payment
await TMATracks.trackPayment({
  amount: 100,
  paymentId: 'payment_123'
})

3. Get UTM Parameter

// Get current UTM parameter
const utm = TMATracks.getUtmParameter()
console.log('User came from:', utm)

🎯 Features

  • Automatic app open tracking - Tracks when users open your app via UTM links
  • Payment tracking - Track revenue and attribute it to UTM sources
  • Telegram user detection - Automatically extracts user info from Telegram WebApp
  • UTM parameter extraction - Decodes base64url UTM from startapp parameter
  • TypeScript support - Full type definitions included
  • Lightweight - ~3KB minified + gzipped
  • No dependencies - Works standalone

📚 API Reference

TMATracks.init(config)

Initialize the SDK. Must be called before any other methods.

Parameters:

  • config.apiKey (string, required) - Your API key
  • config.apiEndpoint (string, required) - Your tracker server URL
  • config.debug (boolean, optional) - Enable debug logging (default: false)
  • config.maxRetries (number, optional) - Max retry attempts for failed requests (default: 3)

Returns: Promise<void>

Example:

await TMATracks.init({
  apiKey: 'your-api-key',
  apiEndpoint: 'https://tracker.example.com',
  debug: process.env.NODE_ENV === 'development'
})

TMATracks.trackPayment(params)

Track a payment event.

Parameters:

  • params.amount (number, required) - Payment amount
  • params.paymentId (string, required) - Unique payment identifier

Returns: Promise<void>

Example:

await TMATracks.trackPayment({
  amount: 99.99,
  paymentId: 'pay_abc123'
})

TMATracks.getUtmParameter()

Get the current UTM parameter.

Returns: string | null - UTM parameter or null if not found

Example:

const utm = TMATracks.getUtmParameter()
if (utm) {
  console.log('User source:', utm)
}

TMATracks.isInitialized()

Check if SDK is initialized.

Returns: boolean

Example:

if (TMATracks.isInitialized()) {
  await TMATracks.trackPayment({ amount: 100, paymentId: 'pay_123' })
}

🔗 How UTM Tracking Works

  1. Create UTM link:

    https://t.me/YourBot/app?startapp=utm_source_123
  2. SDK extracts UTM:

    • Reads startapp parameter from Telegram WebApp
    • Decodes base64url if needed
    • Stores UTM parameter
  3. Automatic tracking:

    • App open event sent automatically on init
    • Payment events linked to UTM source

🛠️ TypeScript

Full TypeScript support with type definitions:

import TMATracks, { TMATracksConfig, PaymentParams } from '@tma-tracker/client'

const config: TMATracksConfig = {
  apiKey: 'key',
  apiEndpoint: 'https://...',
  debug: true
}

const payment: PaymentParams = {
  amount: 100,
  paymentId: 'pay_123'
}

📦 Bundle Formats

  • ESM: dist/index.esm.js - For modern bundlers (Vite, Webpack 5+)
  • CommonJS: dist/index.js - For Node.js and older bundlers
  • UMD: dist/index.umd.js - For CDN usage (browser global)

🌐 CDN Usage (Alternative)

If you prefer CDN over npm:

<script src="https://your-tracker-server.com/sdk/tma-tracker.min.js"></script>
<script>
  TMATracks.init({
    apiKey: 'your-key',
    apiEndpoint: 'https://your-tracker-server.com'
  })
</script>

📄 License

MIT

🔗 Links