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

ga4-telegram-toolkit

v1.0.6

Published

Thư viện hỗ trợ tương tác với Google Analytics 4 và Telegram API

Downloads

15

Readme

GA4 Telegram Toolkit

Thư viện hỗ trợ tương tác với Google Analytics 4 và Telegram API.

npm version License: MIT

Cài đặt

npm install ga4-telegram-toolkit

Sử dụng

Import thư viện

// Import đầy đủ
import { GA4Service, TelegramService, GAInsightsService } from 'ga4-telegram-toolkit';

// Hoặc import từng module riêng biệt
import { GA4Service } from 'ga4-telegram-toolkit';
import { TelegramService } from 'ga4-telegram-toolkit';

Kết nối Google Analytics 4

// Khởi tạo GA4Service với Property ID
const ga4PropertyId = process.env.GA4_PROPERTY_ID || '489280622';
const ga4Service = new GA4Service(ga4PropertyId, 'MyWebsite');

// Lấy báo cáo người dùng theo quốc gia
const usersByCountry = await ga4Service.getUsersByCountry();

// Lấy phiên theo thiết bị
const deviceSessions = await ga4Service.getSessionsByDeviceCategory('yesterday', 'yesterday');

// Lấy trang phổ biến nhất (7 ngày qua)
const topPages = await ga4Service.getPopularPagesWithEngagement('7daysAgo', 'yesterday', 5);

// So sánh lưu lượng hôm nay và hôm qua
const trafficComparison = await ga4Service.compareTodayVsYesterday('sessions');

Gửi tin nhắn qua Telegram

// Khởi tạo TelegramService (cần cấu hình biến môi trường)
// TELEGRAM_BOT_TOKEN=your_bot_token
// TELEGRAM_CHAT_ID=your_chat_id
const telegramService = new TelegramService();

// Gửi tin nhắn đơn giản
await telegramService.sendMessage('Hello from GA4 Telegram Toolkit!');

// Gửi tin nhắn với định dạng HTML
await telegramService.sendMessage('<b>Báo cáo GA4</b>\n<i>Thông tin quan trọng</i>', 'HTML');

// Kiểm tra kết nối
const isConnected = await telegramService.testConnection();

Tạo báo cáo GA4 và gửi qua Telegram

// Khởi tạo service tích hợp
const gaInsightsService = new GAInsightsService();

// Gửi báo cáo GA4 hàng ngày
await gaInsightsService.sendDailyGAInsights();

// Kiểm tra kết nối
await gaInsightsService.testConnection();

Sử dụng Proxy SOCKS5 (tùy chọn)

// Cấu hình biến môi trường để sử dụng proxy
// USE_PROXY=true
// SOCKS5_PROXY_URL=socks5://user:pass@host:port

Usage with Service Account Object

You can now initialize GA4Service with a service account object (only dynamic fields required):

import { GA4Service } from './src/ga.service';

const serviceAccountObj = {
  project_id: 'lynx-460617',
  private_key_id: 'xxxx',
  private_key: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
  client_email: '[email protected]',
  client_id: 'xxxx',
  client_x509_cert_url: 'https://www.googleapis.com/robot/v1/metadata/x509/ga4-xxx%40lynx-460617.iam.gserviceaccount.com'
};

const ga4Service = new GA4Service(
  'YOUR_GA4_PROPERTY_ID',
  'GA4Service',
  undefined, // keyFilePath
  false,     // debug
  serviceAccountObj // pass the object here
);

If you use a file path, the old way still works and the fixed fields will be auto-merged if missing.

Cấu hình môi trường

Tạo file .env với nội dung:

GA4_PROPERTY_ID=your_property_id
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
USE_PROXY=false
SOCKS5_PROXY_URL=

Links

License

MIT