同意に基づくコンバージョン計測:GA4、Meta ピクセル + CAPI、TikTok ピクセル + Events API、重複排除
インストール
genpm add @core/pixels含まれるもの
- src/lib/pixels/ にソースコード(7 ファイル)。 (21.2 KB)
- src/lib/pixels/AGENTS.md に AI ルール、加えて IDE 用のルールファイル。
- .env.example に追加される環境変数: GA4_MEASUREMENT_ID, GA4_API_SECRET, META_PIXEL_ID, META_CAPI_TOKEN, TIKTOK_PIXEL_ID, TIKTOK_EVENTS_TOKEN。
- @core/antispam, @core/consent, @core/contracts, @core/db, @core/money を自動で解決します。
README
このパッケージには README がありません。
これは AI が src/lib/pixels で作業するときに読む内容そのものです。それ以外はコンテキストに追加されません。
@core/pixels — rules for AI agents
Purpose
One place to measure business events (view_item, add_to_cart, begin_checkout, purchase, lead from
@core/contracts) in GA4, Meta and TikTok: browser pixels loaded only inside ConsentGate (@core/consent) and
server-side events (GA4 Measurement Protocol, Meta Conversions API, TikTok Events API) sent only with consent, with
the same eventId on both sides so platforms deduplicate. Emails/phones are SHA-256 hashed. Never throws on vendor errors.
Map
index.ts— server:trackServer,attributionFromRequest,saveAttribution,takeAttribution,browserCalls,registerPixelPlatform.client.ts— client:PixelScripts,track,newEventId.browser.ts—browserCalls(no server code; safe in the browser).schema.ts—pixel_attributions(consent + first-party ids kept until the payment webhook, 7 days).
Integration
- Env (all optional; a platform is active only with both of its vars):
GA4_MEASUREMENT_ID+GA4_API_SECRET,META_PIXEL_ID+META_CAPI_TOKEN(optionalMETA_GRAPH_VERSION,META_TEST_EVENT_CODE),TIKTOK_PIXEL_ID+TIKTOK_EVENTS_TOKEN. Check each platform's current API version and event names before going live. - Layout:
<ConsentGate category="analytics"><PixelScripts ga4MeasurementId=… /></ConsentGate>and<ConsentGate category="marketing"><PixelScripts metaPixelId=… tiktokPixelId=… /></ConsentGate>.PixelScriptsrenders nothing: once mounted (i.e. with consent) it injects each platform's loader into<head>once per page, so re-mounts don't repeatconfig/PageView. A CSP must allow those script and connect origins. - Browser events:
const eventId = newEventId(); track({ type: 'add_to_cart', eventId, … })and send the sameeventIdto the server if it also tracks it. - Purchases: after
startCheckoutreturns{ sessionId },saveAttribution("checkout:" + sessionId, attributionFromRequest(req)); when the order is paid (@core/ordersonOrderEvent('paid')),trackServer(purchaseEvent(order), await takeAttribution("checkout:" + order.cartId))(@core/checkout stores the Stripe session id inorder.cartId;purchaseEventcomes from @core/checkout). - Verify with each platform's test tools (GA4 DebugView, Meta Test Events, TikTok Test Events).
Conventions
- List in the privacy policy what each platform receives (events, hashed email, IP, user agent, click ids).
- Use real values only;
purchaseuses the order total and the order id.
Don't
- Don't load pixels or call
trackServerwithout the matching consent category. - Don't send raw emails, phones, names or addresses to ad platforms.
- Don't invent events (fake purchases to "train" campaigns) or fire
purchasefrom the success page without an order.
# @core/pixels — rules for AI agents
## Purpose
One place to measure business events (`view_item`, `add_to_cart`, `begin_checkout`, `purchase`, `lead` from
@core/contracts) in GA4, Meta and TikTok: browser pixels loaded only inside `ConsentGate` (@core/consent) and
server-side events (GA4 Measurement Protocol, Meta Conversions API, TikTok Events API) sent only with consent, with
the same `eventId` on both sides so platforms deduplicate. Emails/phones are SHA-256 hashed. Never throws on vendor errors.
## Map
- `index.ts` — server: `trackServer`, `attributionFromRequest`, `saveAttribution`, `takeAttribution`, `browserCalls`, `registerPixelPlatform`.
- `client.ts` — client: `PixelScripts`, `track`, `newEventId`. `browser.ts` — `browserCalls` (no server code; safe in the browser).
- `schema.ts` — `pixel_attributions` (consent + first-party ids kept until the payment webhook, 7 days).
## Integration
1. Env (all optional; a platform is active only with both of its vars): `GA4_MEASUREMENT_ID` + `GA4_API_SECRET`,
`META_PIXEL_ID` + `META_CAPI_TOKEN` (optional `META_GRAPH_VERSION`, `META_TEST_EVENT_CODE`), `TIKTOK_PIXEL_ID` + `TIKTOK_EVENTS_TOKEN`.
Check each platform's current API version and event names before going live.
2. Layout: `<ConsentGate category="analytics"><PixelScripts ga4MeasurementId=… /></ConsentGate>` and
`<ConsentGate category="marketing"><PixelScripts metaPixelId=… tiktokPixelId=… /></ConsentGate>`.
`PixelScripts` renders nothing: once mounted (i.e. with consent) it injects each platform's loader into `<head>` once
per page, so re-mounts don't repeat `config`/`PageView`. A CSP must allow those script and connect origins.
3. Browser events: `const eventId = newEventId(); track({ type: 'add_to_cart', eventId, … })` and send the same `eventId` to the server if it also tracks it.
4. Purchases: after `startCheckout` returns `{ sessionId }`, `saveAttribution("checkout:" + sessionId, attributionFromRequest(req))`;
when the order is paid (@core/orders `onOrderEvent('paid')`), `trackServer(purchaseEvent(order), await takeAttribution("checkout:" + order.cartId))`
(@core/checkout stores the Stripe session id in `order.cartId`; `purchaseEvent` comes from @core/checkout).
5. Verify with each platform's test tools (GA4 DebugView, Meta Test Events, TikTok Test Events).
## Conventions
- List in the privacy policy what each platform receives (events, hashed email, IP, user agent, click ids).
- Use real values only; `purchase` uses the order total and the order id.
## Don't
- Don't load pixels or call `trackServer` without the matching consent category.
- Don't send raw emails, phones, names or addresses to ad platforms.
- Don't invent events (fake purchases to "train" campaigns) or fire `purchase` from the success page without an order.
.genpmignore 適用後に組み込まれる正確なツリーです。固定先:
MIT License
Copyright (c) 2026 GenPM
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
このパッケージは MCP サーバーを宣言していません。
| バージョン | コミット | 公開日 | スキャン |
|---|---|---|---|
| 1.0.1 | abb4ca2 | 4 時間前 | スキャン合格 |
- genpm
- @core/antispam ^1.0.0@core/consent ^1.0.0@core/contracts ^1.0.0@core/db ^1.0.0@core/money ^1.0.0
- 提案
- GenPM は npm コマンドを提案し、あなたが承認した場合にのみ実行します。
- 利用元(1)
- @core/kit-landing ^1.0.0
- スキャン
- スキャン合格 · 指摘 0 件
- コミット
- v1.0.1 → abb4ca25745fd3d140e351fc27ecbcccb9f334f4 · 取得後に検証済み
- スクリプト
- なし。GenPM はパッケージのコードを実行しません。
- ライセンス
- MIT
- 品質
- 100/100
- 認識されたライセンス達成
- AGENTS.md に目的の説明がある達成
- AGENTS.md に統合手順がある達成
- AGENTS.md に規約や禁止事項がある達成
- テストを含む達成
- セキュリティスキャンに合格達成
- 過去 6 か月以内に公開達成
- 認証済みの公開者達成
- 概要とキーワード達成
- 報告
- 問題を見つけましたか?