@adkit.so/meta-pixel

中文文档
1.1.5发布于 2025/11/26MITTypeScriptES Module零依赖近 30 天下载 2919

Platform-agnostic Meta Pixel tracking wrapper with TypeScript support

此软件包已被标记为弃用

Renamed to @adkit/meta-pixel. Install that instead; the API is unchanged.

原始使用文档
文档目录26 节
  1. 📚 Table of Contents
  2. ✨ Features
  3. ⚡ Quick Start
  4. 📦 Installation
  5. 💡 Usage
  6. Basic Initialization
  7. Tracking Events
  8. Multiple Instances
  9. ⚙️ Configuration
  10. Configuration Options
  11. Multiple Pixels Example
  12. 📊 Standard Events
  13. 📋 Event Data Parameters
  14. 🚀 Advanced Usage
  15. Event Deduplication
  16. Check if Pixel is Loaded
  17. Debug Mode
  18. 📝 TypeScript Support
  19. ❓ Troubleshooting
  20. Pixel not loading?
  21. Events not showing in Meta Events Manager?
  22. 📚 Official Documentation
  23. 🔗 Platform Packages
  24. 📖 Full Guide
  25. 🤝 Contributing
  26. 📄 License

Meta Pixel (JS/TS)

npm version npm downloads License: MIT

The most powerful and developer-friendly Meta Pixel integration for JavaScript & TypeScript applications.

A platform-agnostic wrapper for Meta Pixel that provides a seamless, type-safe experience with advanced features like event deduplication, multiple pixel support, and beautiful debug logging.

📚 Table of Contents

✨ Features

  • ✅ Typescript Support - Full TypeScript support with autocomplete for all official events and parameters
  • 🎯 Custom Events Support - Track custom events with full type safety and flexible data structures
  • 🚦 Event Deduplication - Support for preventing duplicate events with event IDs
  • 🔌 Multiple Pixels Support - Load and manage multiple pixel IDs effortlessly
  • 🐛 Debug Mode - Beautiful styled console logs for development and debugging
  • 🏠 Localhost Support - Easy configuration to enable/disable tracking on localhost

⚡ Quick Start

npm install @adkit.so/meta-pixel
import META from '@adkit.so/meta-pixel';

// 1. Initialize
META.init({ pixelIds: 'YOUR_PIXEL_ID' });

// 2. Track events
META.track('Purchase', { value: 99.99, currency: 'USD' });

That's it! 🎉

📦 Installation

npm install @adkit.so/meta-pixel

💡 Usage

Basic Initialization

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

import META from '@adkit.so/meta-pixel';

META.init({
    pixelIds: '1234567890',
    autoTrackPageView: true, // default: true
});

Tracking Events

// Track standard events
META.track('AddToCart', {
    value: 29.99,
    currency: 'USD',
    content_ids: ['SKU_123'],
    content_type: 'product',
});

// Track custom events
META.trackCustom('MyCustomEvent', {
    custom_param: 'value',
});

Multiple Instances

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

import { createMetaPixel } from '@adkit.so/meta-pixel';

const marketingPixel = createMetaPixel();
marketingPixel.init({ pixelIds: 'MARKETING_ID' });

const productPixel = createMetaPixel();
productPixel.init({ pixelIds: 'PRODUCT_ID' });

⚙️ Configuration

Configuration Options

OptionTypeDefaultDescription
pixelIdsstring | string[]''Required. Single pixel ID or array of pixel IDs
autoTrackPageViewbooleantrueAutomatically track PageView on initialization
debugbooleanfalseEnable styled console logs with background colors
enableLocalhostbooleanfalseEnable tracking on localhost (useful for testing)

Multiple Pixels Example

META.init({
    pixelIds: ['PIXEL_ID_1', 'PIXEL_ID_2', 'PIXEL_ID_3'],
    debug: true,
});

📊 Standard Events

All Meta Pixel standard events are supported with full TypeScript autocomplete. These events help you track important actions on your website and optimize your ad campaigns.

EventDescriptionCommon Use Cases
AddPaymentInfoPayment info addedCheckout flow
AddToCartItem added to shopping cartE-commerce
AddToWishlistItem added to wishlistE-commerce
CompleteRegistrationUser completed registrationSign-ups, account creation
ContactUser contacted businessContact forms
CustomizeProductProduct customization startedProduct configurators
DonateDonation madeNon-profits
FindLocationLocation finder usedStore locators
InitiateCheckoutCheckout process startedE-commerce funnels
LeadLead submittedLead generation forms
PurchasePurchase completedTransaction confirmation
ScheduleAppointment scheduledBooking systems
SearchSearch performedSite search
StartTrialTrial startedSaaS applications
SubmitApplicationApplication submittedJob boards, loan applications
SubscribeSubscription startedNewsletters, subscriptions
ViewContentContent viewedProduct pages, blog posts

You can find the official list of standard events here.

📋 Event Data Parameters

All event parameters are optional but help improve ad targeting and conversion tracking.

ParameterTypeDescriptionExample
valuenumberMonetary value of the event99.99
currencystringISO 4217 currency code'USD', 'EUR', 'GBP'
content_idsstring[]Product IDs or SKUs['SKU_123', 'SKU_456']
content_typestringType of content'product', 'product_group'
content_namestringName of page/product'Blue T-Shirt'
content_categorystringCategory of page/product'Apparel', 'Electronics'
contentsArray<{id, quantity}>Detailed product information[{id: 'SKU_123', quantity: 2}]
num_itemsnumberNumber of items3
search_stringstringSearch query'running shoes'
statusbooleanRegistration/subscription statustrue
predicted_ltvnumberPredicted lifetime value of customer450.00

You can find the list of properties here

🚀 Advanced Usage

Event Deduplication

Prevent duplicate event tracking by using unique event IDs. This is crucial when tracking conversions from both client and server (CAPI).

const orderId = '12345';

META.track(
    'Purchase',
    {
        value: 299.99,
        currency: 'USD',
        content_ids: ['SKU_123'],
    },
    {
        eventID: `order-${orderId}`, // Unique Event ID
    },
);

Check if Pixel is Loaded

Useful if you need to conditionally run logic based on whether the pixel script has loaded.

if (META.isLoaded()) {
    META.track('Purchase', { value: 99.99, currency: 'USD' });
} else {
    console.log('Pixel not loaded yet');
}

Debug Mode

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

  • 🔵 [Meta Pixel] Info messages (blue background)
  • ✅ [Meta Pixel] Success messages (green background)
  • ⚠️ [Meta Pixel] Warning messages (orange background)
META.init({
    pixelIds: 'YOUR_ID',
    debug: true,
});

📝 TypeScript Support

This package is written in TypeScript and bundles type definitions.

import type { StandardEvent, EventData, MetaPixelConfig } from '@adkit.so/meta-pixel';

const config: MetaPixelConfig = {
    pixelIds: '123',
};

const eventData: EventData = {
    value: 100,
    currency: 'USD',
};

❓ Troubleshooting

Pixel not loading?

  1. Check your pixel ID - Make sure it's correct in your config
  2. Enable debug mode - Set debug: true in init() to see detailed logs
  3. Check browser console - Look for errors or warnings
  4. Check Ad Blockers - Ad blockers often block the Meta Pixel script
  5. Enable on localhost - Set enableLocalhost: true if testing locally

Events not showing in Meta Events Manager?

  • Wait a few minutes - Events can take 5-20 minutes to appear
  • Check Test Events - Use the Test Events tool in Meta Events Manager
  • Verify event names - Standard events are case-sensitive

📚 Official Documentation

Learn more about Meta Pixel from official Facebook resources:

🔗 Platform Packages

Using a framework? Check out our dedicated packages:

  • Nuxt - @adkit.so/meta-pixel-nuxt
  • React - @adkit.so/meta-pixel-react
  • Next.js - @adkit.so/meta-pixel-next

📖 Full Guide

For a complete step-by-step guide on installing and configuring Meta Pixel, check out our detailed tutorial:

How to Install Meta Pixel

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

MIT


Made with ❤️ by Adkit

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

版本与发布记录

@adkit.so/meta-pixel 共发布 11 个版本,首次发布于 2025/11/07;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.1.5latest2025/11/2611 个月前
1.1.42025/11/2411 个月前
1.1.32025/11/2411 个月前
1.1.22025/11/2411 个月前
1.1.12025/11/2411 个月前
1.0.32025/11/071 年前

关于 @adkit.so/meta-pixel 的常见问题

@adkit.so/meta-pixel 是什么?

Platform-agnostic Meta Pixel tracking wrapper with TypeScript support注意:该包已被作者标记为弃用——Renamed to @adkit/meta-pixel. Install that instead; the API is unchanged.

如何安装 @adkit.so/meta-pixel?

在项目目录运行 npm install @adkit.so/meta-pixel,或使用 pnpm add / yarn add / bun add。

@adkit.so/meta-pixel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adkit.so/meta-pixel 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adkit.so/meta-pixel 可以商用吗?

@adkit.so/meta-pixel 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adkit.so/meta-pixel 的下载量有多少?

根据 npm 官方下载统计,@adkit.so/meta-pixel 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,919 次,日均约 97 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adkit.so/meta-pixel 还在维护吗?

最新版本 1.1.5 发布于 2025/11/26(11 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/11/07。作者已将其标记为弃用,新项目建议寻找替代方案。