sfnext-analytics-consent
БесплатноБез исполняемых скриптовНе проверенStorefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker…
от SalesforceCommerceCloud★ 58 звёзд на GitHubОб этом скилле
Storefront Next Analytics and Consent
Events flow: component -> useAnalytics() -> event mediator (@salesforce/storefront-next-runtime/events) -> each registered engagement adapter. Every adapter checks shopper consent before sending. Read docs/README-ADAPTER-PATTERN-GUIDE.md and docs/README-CONSENT-TRACKING.md in your project for the full guides; where they disagree with the code, trust the code (paths below were verified).
Where things live
| Concern | Location |
|---|---|
| Adapter config | engagement.adapters.* in config.server.ts |
Adapter types, store, hasConsent, buildConsentPreferences |
@/lib/adapters (src/lib/adapters/engagement/) |
| Registration of built-in adapters | src/lib/adapters/engagement/register.ts (initializeEngagementAdapters) |
| Built-in adapters | einstein.ts, active-data.ts, data360.ts in the same folder |
| Page view tracking | src/analytics/page-view-tracker.tsx (PageViewTracker, mounted in src/root.tsx) |
| Event hooks | @/hooks/use-analytics, @/hooks/use-tracking-consent |
| Attribution | src/lib/attribution.ts, @/hooks/use-attribution, src/middlewares/attribution-forwarding.server.ts |
Configure built-in adapters
// config.server.ts
engagement: {
adapters: {
einstein: { enabled: true, consentCategory: 'analytics', host, einsteinId, realm, siteId, isProduction: false,
eventToggles: { view_page: true, view_product: true /* ... */ } },
data360: { enabled: true, consentCategory: 'analytics', appSourceId, tenantId, siteId, webStoreId: 'sfnext', eventToggles: { /* ... */ } },
activeData: { enabled: true, /* see config.server.ts */ },
},
analytics: {
trackingConsent: { enabled: true, defaultTrackingConsent: TrackingConsent.Declined,
consentCategories: ['necessary', 'analytics', 'marketing', 'personalization'] },
pageViewsBlocklist: [/* paths that must not emit view_page */],
},
}
- The shipped IDs (einsteinId, realm, tenantId, ...) are sample values. Replace them with your own before go-live, or set
enabled: false. - An adapter with
consentCategory: 'analytics'sends nothing unless'analytics'is intrackingConsent.consentCategories. eventTogglesturns individual event types on or off per adapter. Data 360 ships only view/impression events enabled.- The
einsteinanddata360adapter blocks, andactiveData.enabled/activeData.eventToggles, are protected config paths and cannot be overridden withPUBLIC__env vars; editconfig.server.tsand rebuild. Other keys follow thePUBLIC__app__engagement__...pattern (seestorefront-next:sfnext-configuration).
Fire events
import { useAnalytics } from '@/hooks/use-analytics';
const { trackViewProduct, trackCartItemAdd } = useAnalytics();
useAnalytics returns trackViewPage, trackViewProduct, trackCartItemAdd, trackCheckoutStart, trackCheckoutStep, trackViewSearch, trackViewCategory, trackClickProductIn{Category,Search,Recommender}, trackViewRecommender, search-suggestion and wishlist trackers. On the server these are no-ops, so call them from effects or event handlers. Check the hook source for exact argument shapes before calling.
Consent
Consent is read from the auth session (dw_dnt cookie) by useTrackingConsent(), converted to a ConsentPreferences array by buildConsentPreferences(trackingConsent, consentCategories, isTrackingConsentEnabled), and passed to every adapter. While consent is undetermined or declined, no events are sent.
import { useTrackingConsent } from '@/hooks/use-tracking-consent';
import { TrackingConsent } from '@/types/tracking-consent';
const { shouldShowBanner, setTrackingConsent } = useTrackingConsent();
setTrackingConsent(TrackingConsent.Accepted);
Granular per-category consent (for example from a CMP) means replacing the binary banner logic that feeds buildConsentPreferences; adapters already gate per consentCategory.
Add a custom adapter
See references/CUSTOM-ADAPTER.md. In short: implement createMyAdapter(config): EngagementAdapter using hasConsent, register it with addAdapter('my-adapter', ...) inside initializeEngagementAdapters, and add engagement.adapters.myAdapter config (the config type allows extra keys).
Attribution
A first-touch dw_attribution cookie captures allow-listed landing/referrer params (see LANDING_PARAM_ALLOWLIST in src/lib/attribution.ts). attributionForwardingMiddleware forwards it on order creation. Add a parameter by extending the allowlist; cookie size is capped (MAX_ATTRIBUTION_COOKIE_VALUE_LENGTH).
Troubleshooting
- No events at all: consent not accepted,
'analytics'missing fromconsentCategories, adapterenabled: false, or the path is inpageViewsBlocklist. Startup logs a warning when consent categories are empty. - Custom adapter never fires: it was not registered in `initializeEnga
Установить sfnext-analytics-consent в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sfnext-analytics-consent?
Storefront Next analytics: engagement adapters (Einstein, Active Data, Data 360), adding a custom adapter, tracking consent gating, PageViewTracker, useAnalytics events, and first-touch attribution (dw_attribution). Use when configuring engagement.adapters in config.server.ts, writing an adapter with hasConsent, registering it in initializeEngagementAdapters, wiring the consent banner (trackingConsent, consentCategories, dw_dnt), firing trackViewProduct/trackCartItemAdd events, debugging why no analytics events are sent, or passing campaign attribution to orders. Do not use for general config loading or env vars (use `storefront-next:sfnext-configuration`), CSP/script allowlisting of third-party tags (use `storefront-next:sfnext-security`), or SEO meta/JSON-LD (use `storefront-next:sfnext-seo`).
Как установить скилл sfnext-analytics-consent?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sfnext-analytics-consent запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic