New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@adkit.so/google-tracking

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adkit.so/google-tracking

Platform-agnostic Google Ads tracking wrapper with TypeScript support

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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

OptionTypeDefaultDescription
tagIdstring | string[]''Required. Single Tag ID or array of Tag IDs (e.g., AW-XXXXX)
debugbooleanfalseEnable styled console logs with background colors
enableLocalhostbooleanfalseEnable tracking on localhost (useful for testing)

Multiple Tags Example

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

📊 Tracking Conversions

Conversion Parameters

ParameterTypeDescriptionExample
valuenumberMonetary value of the conversion99.99
currencystringISO 4217 currency code'USD', 'EUR'
transaction_idstringUnique 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?

  • Check your Tag ID - Make sure it's correct (format: AW-XXXXXXXXXX)
  • Check Conversion ID - Full format: AW-XXXXXXXXXX/CONVERSION_LABEL
  • Enable debug mode - Set debug: true in init() to see detailed logs
  • Check browser console - Look for errors or warnings
  • Check Ad Blockers - Ad blockers may block Google tracking scripts
  • 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:

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!

Keywords

google

FAQs

Package last updated on 03 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts