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

@adkit.so/google-tracking

v1.0.2

Published

Platform-agnostic Google Ads tracking wrapper with TypeScript support

Readme

Google Ads Tracking (JS/TS)

npm version npm downloads License: MIT

A lightweight, type-safe Google Ads (gtag.js) tracking wrapper for JavaScript & TypeScript applications.

Platform-agnostic wrapper for Google Ads conversion tracking with TypeScript support, debug logging, and automatic script loading.

📚 Table of Contents

✨ Features

  • TypeScript Support - Full TypeScript support with type definitions
  • 🎯 Conversion Tracking - Easy Google Ads conversion tracking with flexible parameters
  • 🔌 Auto Script Loading - Automatically loads gtag.js script
  • 🐛 Debug Mode - Beautiful styled console logs for development
  • 🏠 Localhost Support - Easy configuration to enable/disable tracking on localhost
  • 📦 Lightweight - Minimal footprint (~2KB minified)

⚡ Quick Start

npm install @adkit.so/google-tracking
import GOOGLE from '@adkit.so/google-tracking';

// 1. Initialize
GOOGLE.init({ tagId: 'AW-XXXXXXXXXX' });

// 2. Track conversions
GOOGLE.trackConversion('AW-XXXXXXXXXX/YYYYYYY', { value: 29.99, currency: 'USD' });

That's it! 🎉

📦 Installation

npm install @adkit.so/google-tracking

💡 Usage

Basic Initialization

Initialize the tracker as early as possible in your application entry point (e.g., main.ts, App.jsx, index.js).

import GOOGLE from '@adkit.so/google-tracking';

GOOGLE.init({
    tagId: 'AW-XXXXXXXXXX',
    debug: true, // Enable console logs
    enableLocalhost: true, // Enable on localhost for testing
});

Tracking Conversions

// Basic conversion (no value)
GOOGLE.trackConversion('AW-XXXXXXXXXX/CONVERSION_LABEL');

// Conversion with value
GOOGLE.trackConversion('AW-XXXXXXXXXX/CONVERSION_LABEL', {
    value: 99.99,
    currency: 'USD',
});

// Conversion with transaction ID (for deduplication)
GOOGLE.trackConversion('AW-XXXXXXXXXX/CONVERSION_LABEL', {
    value: 99.99,
    currency: 'USD',
    transaction_id: 'ORDER_12345',
});

Multiple Instances

If you need separate instances for different parts of your application:

import { createGoogleTracking } from '@adkit.so/google-tracking';

const tracker1 = createGoogleTracking();
tracker1.init({ tagId: 'AW-FIRST_TAG' });

const tracker2 = createGoogleTracking();
tracker2.init({ tagId: 'AW-SECOND_TAG' });

⚙️ Configuration

Configuration Options

| Option | Type | Default | Description | | ----------------- | -------------------- | ------- | -------------------------------------------------------------- | | tagId | string \| string[] | '' | Required. Single Tag ID or array of Tag IDs (e.g., AW-XXXXX) | | debug | boolean | false | Enable styled console logs with background colors | | enableLocalhost | boolean | false | Enable tracking on localhost (useful for testing) |

Multiple Tags Example

GOOGLE.init({
    tagId: ['AW-FIRST_TAG', 'AW-SECOND_TAG'],
    debug: true,
});

📊 Tracking Conversions

Conversion Parameters

| Parameter | Type | Description | Example | | ---------------- | -------- | ------------------------------- | ---------------- | | value | number | Monetary value of the conversion | 99.99 | | currency | string | ISO 4217 currency code | 'USD', 'EUR' | | transaction_id | string | Unique ID for deduplication | 'ORDER_12345' |

Common Conversion Examples

// E-commerce purchase
GOOGLE.trackConversion('AW-XXXXX/purchase_label', {
    value: 149.99,
    currency: 'USD',
    transaction_id: 'order_abc123',
});

// Lead form submission
GOOGLE.trackConversion('AW-XXXXX/lead_label');

// Sign-up conversion
GOOGLE.trackConversion('AW-XXXXX/signup_label', {
    value: 10.0,
    currency: 'USD',
});

// Subscription conversion
GOOGLE.trackConversion('AW-XXXXX/subscribe_label', {
    value: 29.0,
    currency: 'USD',
    transaction_id: 'sub_xyz789',
});

🚀 Advanced Usage

Check if Loaded

Useful if you need to conditionally run logic based on whether gtag has loaded.

if (GOOGLE.isLoaded()) {
    GOOGLE.trackConversion('AW-XXXXX/label');
} else {
    console.log('Google Ads not loaded yet');
}

Get Current Configuration

const config = GOOGLE.getConfig();
console.log(config?.tagId); // 'AW-XXXXX'

Debug Mode

When debug: true is passed to init(), you'll see beautiful styled console logs:

  • 🔵 [Google Tracking] Info messages (blue background)
  • [Google Tracking] Success messages (green background)
  • ⚠️ [Google Tracking] Warning messages (orange background)
GOOGLE.init({
    tagId: 'AW-XXXXX',
    debug: true,
});

📝 TypeScript Support

This package is written in TypeScript and bundles type definitions.

import type { GoogleTrackingConfig, ConversionParams } from '@adkit.so/google-tracking';

const config: GoogleTrackingConfig = {
    tagId: 'AW-XXXXX',
    debug: true,
};

const params: ConversionParams = {
    value: 100,
    currency: 'USD',
    transaction_id: 'order_123',
};

❓ Troubleshooting

Conversions not tracking?

  1. Check your Tag ID - Make sure it's correct (format: AW-XXXXXXXXXX)
  2. Check Conversion ID - Full format: AW-XXXXXXXXXX/CONVERSION_LABEL
  3. Enable debug mode - Set debug: true in init() to see detailed logs
  4. Check browser console - Look for errors or warnings
  5. Check Ad Blockers - Ad blockers may block Google tracking scripts
  6. Enable on localhost - Set enableLocalhost: true if testing locally

Conversions not showing in Google Ads?

  • Wait up to 24 hours - Conversions can take time to appear
  • Check Google Tag Assistant - Use the Chrome extension to verify tags
  • Verify conversion action - Ensure the conversion is set up in Google Ads

📚 Official Documentation

Learn more about Google Ads conversion tracking:

🔗 Related Packages

Check out our other tracking packages:

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT


Made with ❤️ by AdKit

If this package helped you, please consider giving it a ⭐️ on GitHub!