@amboras-dev/google-ads

中文文档
1.2.1发布于 2026/11/02TypeScriptESM + CJS近 30 天下载 1.5万

Google Ads (gtag.js conversion tracking + Enhanced Conversions + Consent Mode) hooks for Amboras storefronts

原始使用文档
文档目录6 节
  1. Install
  2. What's tracked
  3. Architecture
  4. Multi-currency
  5. Enhanced Conversions & consent
  6. Programmatic API

@amboras-dev/google-ads

Google Ads conversion tracking for Amboras storefronts — the Amboras equivalent of the "Google Ads Pixel by Nabu" Shopify app. Fully client-side via Google's tag (gtag.js): conversion tracking, Enhanced Conversions, Consent Mode v2, deterministic dedup, and accurate multi-currency conversion values.

Install

pnpm add @amboras-dev/google-ads

What's tracked

StageEventSlotClass
Load tag (after consent) + Consent Modepage_viewrootProvidersA (GoogleAdsProvider)
Product viewview_itempdpAnalyticsA (GoogleAdsViewItem)
Add to cartadd_to_cartcartUpdateB (tracker template)
Begin checkoutbegin_checkoutcheckoutStartB (tracker template)
PurchasepurchasecheckoutCompleteB (tracker template)

Each conversion fires gtag('event', 'conversion', { send_to: 'AW-XXXX/<label>', value, currency, transaction_id, items }). The conversion id and per-action conversion labels come from the merchant's admin settings, served by GET /store/google-ads/config.

Architecture

  • GoogleAdsProvider (Class A, rootProviders) — self-fetches config and waits for the amboras_consent cookie to grant analytics (re-checked on amboras-consent-changed). Only then does it set the Consent Mode v2 signals, load the AW- tag once (DOM-idempotent), enable Enhanced Conversions, and stash {conversionId, labels, enhancedConversions} on window.__amborasGoogleAds. Before consent no gtag, dataLayer or AW- script exists on the page.
  • GoogleAdsViewItem (Class A, pdpAnalytics) — fires view_item.
  • Class B trackers (add-to-cart / begin-checkout / purchase) read real cart.items / order line items + customer email/phone from local React scope, so values and item ids are correct (the slot context alone only exposes {cartId,itemCount,total,currency}).

Multi-currency

Every event carries the buyer's real currency_code and a value scaled by that currency's own decimal count via toMajorUnits(amount, currency) (Intl-based) — not a blind /100. JPY/KRW (0-decimal) and KWD/BHD (3-decimal) are correct.

  • First-party data (email, phone_number) is forwarded raw to gtag('set','user_data',…); Google's tag normalises + SHA-256 hashes it client-side. Nothing sensitive leaves the browser unhashed and no server relay is involved.
  • The tag and all conversions are gated on amboras_consent.analytics. Nothing loads or fires until it is true: an absent cookie (no banner shown yet, or no click) counts as denied. The Amboras edge writes a granted cookie automatically for shoppers outside the EEA, UK and Switzerland. Once the tag loads, the Consent Mode v2 signals (ad_storage, ad_user_data, ad_personalization, analytics_storage) mirror that consent.

Programmatic API

import { trackPurchase, cartItemsToItems } from '@amboras-dev/google-ads'

trackPurchase({
  orderId: order.id,
  items: cartItemsToItems(order.items, order.currency_code),
  totalMinor: order.total, // minor units; converted per-currency
  currency: order.currency_code,
  email: order.email,
})

版本与发布记录

@amboras-dev/google-ads 共发布 6 个版本,首次发布于 2026/06/24;过去 12 个月发布了 6 个版本。

版本发布日期距今
1.2.1latest2026/11/023 天前
1.2.02026/10/279 天前
1.1.32026/07/293 个月前
1.1.22026/06/254 个月前
1.1.12026/06/254 个月前
1.1.02026/06/244 个月前

关于 @amboras-dev/google-ads 的常见问题

@amboras-dev/google-ads 是什么?

Google Ads (gtag.js conversion tracking + Enhanced Conversions + Consent Mode) hooks for Amboras storefronts

如何安装 @amboras-dev/google-ads?

在项目目录运行 npm install @amboras-dev/google-ads,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amboras-dev/google-ads 支持 TypeScript 吗?

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

@amboras-dev/google-ads 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@amboras-dev/google-ads 可以商用吗?

@amboras-dev/google-ads 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@amboras-dev/google-ads 的下载量有多少?

根据 npm 官方下载统计,@amboras-dev/google-ads 在 2026/10/06 – 2026/11/04 这 30 天内被下载 14,884 次,日均约 496 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amboras-dev/google-ads 还在维护吗?

最新版本 1.2.1 发布于 2026/11/02(3 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/06/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。