@replohq/sdk 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "X" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "HubSpot" | "Cookiebot" | "snippet" | "custom" | "consentPlatform";
1
+ export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "X" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "Mixpanel" | "HubSpot" | "Cookiebot" | "snippet" | "custom" | "consentPlatform";
2
2
  export type ConsentCategory = "necessary" | "analytics" | "marketing" | "preferences" | "sale_of_data";
3
3
  export type ConsentMode = "off" | "simple" | "per-category";
4
4
  export type ScriptTagDescriptor = {
@@ -19,6 +19,7 @@ export type XPixelEvents = {
19
19
  startCheckout?: string;
20
20
  purchase?: string;
21
21
  };
22
+ export type MixpanelRegion = "us" | "eu" | "in";
22
23
  export type ReploScriptEntry = {
23
24
  type: "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "HubSpot";
24
25
  identifier: string;
@@ -28,6 +29,11 @@ export type ReploScriptEntry = {
28
29
  identifier: string;
29
30
  events?: Partial<XPixelEvents>;
30
31
  requiredConsent?: ConsentCategory[];
32
+ } | {
33
+ type: "Mixpanel";
34
+ identifier: string;
35
+ region?: MixpanelRegion;
36
+ requiredConsent?: ConsentCategory[];
31
37
  } | {
32
38
  type: "Cookiebot";
33
39
  identifier: string;
@@ -4,6 +4,7 @@ import { ConvergeSink } from "./sinks/converge-sink";
4
4
  import { ElevarSink } from "./sinks/elevar-sink";
5
5
  import { GA4Sink } from "./sinks/ga4-sink";
6
6
  import { MetaSink } from "./sinks/meta-sink";
7
+ import { MixpanelSink } from "./sinks/mixpanel-sink";
7
8
  import { NorthbeamSink } from "./sinks/northbeam-sink";
8
9
  import { PinterestSink } from "./sinks/pinterest-sink";
9
10
  import { RedditSink } from "./sinks/reddit-sink";
@@ -23,12 +24,13 @@ const PROVIDER_SINK_FACTORIES = {
23
24
  Reddit: () => new RedditSink(),
24
25
  Northbeam: () => new NorthbeamSink(),
25
26
  Converge: () => new ConvergeSink(),
26
- Segment: () => new SegmentSink()
27
+ Segment: () => new SegmentSink(),
28
+ Mixpanel: () => new MixpanelSink()
27
29
  };
28
30
  const SNIPPET_PROVIDER_SINK_FACTORIES = {
29
31
  [snippetScriptId("Elevar")]: () => new ElevarSink()
30
32
  };
31
- const SHOPIFY_FUNNEL_GATE_EXEMPT_PROVIDERS = /* @__PURE__ */ new Set(["Segment"]);
33
+ const SHOPIFY_FUNNEL_GATE_EXEMPT_PROVIDERS = /* @__PURE__ */ new Set(["Segment", "Mixpanel"]);
32
34
  function findSinkFactory(script) {
33
35
  if (script.type === "X") {
34
36
  return () => {
@@ -0,0 +1,48 @@
1
+ import type { AnalyticsProductLine, CartViewedData, CheckoutStartedData, CollectionViewedData, PurchasePayload } from "../analytics-sink";
2
+ /**
3
+ * Maps Replo's analytics payloads onto Mixpanel's conventional e-commerce
4
+ * property names (the Segment-style vocabulary Mixpanel's docs recommend:
5
+ * `product_id`, `name`, `price`, `quantity`, `products`, `revenue`, ...).
6
+ *
7
+ * Mixpanel accepts any property bag, so unlike the Converge mapper nothing
8
+ * here rejects an event: a funnel built on `Product Viewed` still counts an
9
+ * event whose payload had no price. Empty SKUs and variant titles are left
10
+ * out rather than sent blank.
11
+ */
12
+ export type MixpanelProductProperties = {
13
+ product_id: string;
14
+ sku?: string;
15
+ name?: string;
16
+ variant?: string;
17
+ variant_id?: string;
18
+ price?: number;
19
+ quantity?: number;
20
+ currency?: string;
21
+ };
22
+ export type MixpanelCartProperties = {
23
+ total: number;
24
+ currency?: string;
25
+ products?: MixpanelProductProperties[];
26
+ };
27
+ export type MixpanelOrderProperties = {
28
+ total: number;
29
+ /** The property Mixpanel's revenue reports read. */
30
+ revenue: number;
31
+ currency: string;
32
+ order_id?: string;
33
+ products?: MixpanelProductProperties[];
34
+ tax?: number;
35
+ shipping?: number;
36
+ discount?: number;
37
+ coupon?: string;
38
+ };
39
+ export type MixpanelCollectionProperties = {
40
+ list_id: string;
41
+ name?: string;
42
+ products?: MixpanelProductProperties[];
43
+ };
44
+ export declare function mapMixpanelProduct(line: AnalyticsProductLine): MixpanelProductProperties;
45
+ export declare function mapMixpanelViewedCart(data: CartViewedData): MixpanelCartProperties;
46
+ export declare function mapMixpanelCheckout(data: CheckoutStartedData): MixpanelCartProperties;
47
+ export declare function mapMixpanelCollection(data: CollectionViewedData): MixpanelCollectionProperties;
48
+ export declare function mapMixpanelOrder({ amount, currency, data, }: PurchasePayload): MixpanelOrderProperties;
@@ -0,0 +1,96 @@
1
+ import { filterUndefined } from "../../_vendor/replo-utils/lib/object.mjs";
2
+ import { legacyResourceId } from "../utils/analytics-products";
3
+ function mapProduct({
4
+ line,
5
+ fallbackCurrency
6
+ }) {
7
+ return {
8
+ product_id: legacyResourceId(line.productId),
9
+ ...filterUndefined({
10
+ sku: line.variantSku || void 0,
11
+ name: line.productTitle || void 0,
12
+ variant: line.variantTitle || void 0,
13
+ variant_id: line.variantId ? legacyResourceId(line.variantId) : void 0,
14
+ price: line.price,
15
+ quantity: line.quantity,
16
+ currency: line.currency ?? fallbackCurrency ?? void 0
17
+ })
18
+ };
19
+ }
20
+ function mapProducts({
21
+ lines,
22
+ currency
23
+ }) {
24
+ if (lines.length === 0) {
25
+ return void 0;
26
+ }
27
+ return lines.map((line) => mapProduct({ line, fallbackCurrency: currency }));
28
+ }
29
+ function mapMixpanelProduct(line) {
30
+ return mapProduct({ line, fallbackCurrency: null });
31
+ }
32
+ function mapCart({
33
+ total,
34
+ currency,
35
+ lineItems
36
+ }) {
37
+ return {
38
+ total,
39
+ ...filterUndefined({
40
+ currency: currency ?? void 0,
41
+ products: mapProducts({ lines: lineItems, currency })
42
+ })
43
+ };
44
+ }
45
+ function mapMixpanelViewedCart(data) {
46
+ return mapCart({
47
+ total: data.subtotal,
48
+ currency: data.currency ?? null,
49
+ lineItems: data.lineItems
50
+ });
51
+ }
52
+ function mapMixpanelCheckout(data) {
53
+ return mapCart({
54
+ total: data.total,
55
+ currency: data.currency ?? null,
56
+ lineItems: data.lineItems
57
+ });
58
+ }
59
+ function mapMixpanelCollection(data) {
60
+ return {
61
+ list_id: legacyResourceId(data.collectionId),
62
+ ...filterUndefined({
63
+ name: data.collectionTitle || void 0,
64
+ products: mapProducts({
65
+ lines: data.products,
66
+ currency: data.currency ?? null
67
+ })
68
+ })
69
+ };
70
+ }
71
+ function mapMixpanelOrder({
72
+ amount,
73
+ currency,
74
+ data
75
+ }) {
76
+ return {
77
+ total: amount,
78
+ revenue: amount,
79
+ currency,
80
+ ...filterUndefined({
81
+ order_id: data.orderId || void 0,
82
+ products: mapProducts({ lines: data.lineItems ?? [], currency }),
83
+ tax: data.totalTax,
84
+ shipping: data.totalShipping,
85
+ discount: data.totalDiscount,
86
+ coupon: data.discountCodes && data.discountCodes.length > 0 ? data.discountCodes.join(", ") : void 0
87
+ })
88
+ };
89
+ }
90
+ export {
91
+ mapMixpanelCheckout,
92
+ mapMixpanelCollection,
93
+ mapMixpanelOrder,
94
+ mapMixpanelProduct,
95
+ mapMixpanelViewedCart
96
+ };
@@ -0,0 +1,27 @@
1
+ import type { AnalyticsSink, CartLineEventPayload, CartViewedPayload, CheckoutStartedPayload, ClickPayload, CollectionViewedPayload, CustomEventPayload, LegacyCheckoutStartedPayload, ProductViewedPayload, PurchasePayload } from "../analytics-sink";
2
+ import type { PageMetadata } from "../utils/navigation-tracker";
3
+ declare global {
4
+ interface Window {
5
+ mixpanel?: {
6
+ track: (eventName: string, properties: Record<string, unknown>) => void;
7
+ };
8
+ }
9
+ }
10
+ /**
11
+ * Sends Replo's analytics events to Mixpanel with its conventional e-commerce
12
+ * event names. The consent-gated snippet sends the landing "Page Viewed"; this
13
+ * sink adds one for each in-site navigation, so each load counts once.
14
+ */
15
+ export declare class MixpanelSink implements AnalyticsSink {
16
+ private send;
17
+ customEvent({ event, properties }: CustomEventPayload): Promise<void>;
18
+ pageView(metadata?: PageMetadata): Promise<void>;
19
+ purchase(payload: PurchasePayload): Promise<void>;
20
+ click({ data }: ClickPayload): Promise<void>;
21
+ productViewed({ data }: ProductViewedPayload): Promise<void>;
22
+ addToCart({ data }: CartLineEventPayload): Promise<void>;
23
+ removeFromCart({ data }: CartLineEventPayload): Promise<void>;
24
+ viewCart({ data }: CartViewedPayload): Promise<void>;
25
+ startCheckout(payload: CheckoutStartedPayload | LegacyCheckoutStartedPayload): Promise<void>;
26
+ viewCollection({ data }: CollectionViewedPayload): Promise<void>;
27
+ }
@@ -0,0 +1,99 @@
1
+ import { filterUndefined } from "../../_vendor/replo-utils/lib/object.mjs";
2
+ import { toCheckoutStartedData } from "../legacy-checkout";
3
+ import { createAnalyticsQueue } from "../utils/analytics-utils";
4
+ import {
5
+ mapMixpanelCheckout,
6
+ mapMixpanelCollection,
7
+ mapMixpanelOrder,
8
+ mapMixpanelProduct,
9
+ mapMixpanelViewedCart
10
+ } from "./mixpanel-event-mapper";
11
+ function findMixpanel() {
12
+ if (typeof window === "undefined") {
13
+ return null;
14
+ }
15
+ return window.mixpanel ?? null;
16
+ }
17
+ function pathFromUrl(url) {
18
+ try {
19
+ return new URL(url).pathname;
20
+ } catch {
21
+ return void 0;
22
+ }
23
+ }
24
+ class MixpanelSink {
25
+ send = createAnalyticsQueue({
26
+ isReady: () => Boolean(findMixpanel()),
27
+ send: ({ eventName, properties }) => {
28
+ findMixpanel()?.track(eventName, properties);
29
+ },
30
+ queueName: "Mixpanel"
31
+ });
32
+ async customEvent({ event, properties }) {
33
+ this.send({ eventName: event, properties: properties ?? {} });
34
+ }
35
+ async pageView(metadata) {
36
+ if (metadata?.navigationType === "initial") {
37
+ return;
38
+ }
39
+ const url = metadata?.url ?? (typeof window === "undefined" ? void 0 : window.location.href);
40
+ this.send({
41
+ eventName: "Page Viewed",
42
+ properties: filterUndefined({
43
+ url,
44
+ path: url ? pathFromUrl(url) : void 0,
45
+ title: metadata?.title || void 0,
46
+ referrer: metadata?.referrer || void 0,
47
+ navigation_type: metadata?.navigationType
48
+ })
49
+ });
50
+ }
51
+ async purchase(payload) {
52
+ this.send({
53
+ eventName: "Order Completed",
54
+ properties: mapMixpanelOrder(payload)
55
+ });
56
+ }
57
+ async click({ data }) {
58
+ this.send({ eventName: "Click", properties: data });
59
+ }
60
+ async productViewed({ data }) {
61
+ this.send({
62
+ eventName: "Product Viewed",
63
+ properties: mapMixpanelProduct(data)
64
+ });
65
+ }
66
+ async addToCart({ data }) {
67
+ this.send({
68
+ eventName: "Product Added",
69
+ properties: mapMixpanelProduct(data)
70
+ });
71
+ }
72
+ async removeFromCart({ data }) {
73
+ this.send({
74
+ eventName: "Product Removed",
75
+ properties: mapMixpanelProduct(data)
76
+ });
77
+ }
78
+ async viewCart({ data }) {
79
+ this.send({
80
+ eventName: "Cart Viewed",
81
+ properties: mapMixpanelViewedCart(data)
82
+ });
83
+ }
84
+ async startCheckout(payload) {
85
+ this.send({
86
+ eventName: "Checkout Started",
87
+ properties: mapMixpanelCheckout(toCheckoutStartedData(payload.data))
88
+ });
89
+ }
90
+ async viewCollection({ data }) {
91
+ this.send({
92
+ eventName: "Collection Viewed",
93
+ properties: mapMixpanelCollection(data)
94
+ });
95
+ }
96
+ }
97
+ export {
98
+ MixpanelSink
99
+ };
@@ -1,5 +1,8 @@
1
1
  import type { ConsentCategory, ReploScriptEntry, ReploScriptType, ScriptTagDescriptor } from "../_vendor/schemas/generated/consent";
2
2
  type ProviderType = Exclude<ReploScriptType, "custom" | "snippet" | "consentPlatform" | "Cookiebot">;
3
+ type ProviderScriptEntry = Extract<ReploScriptEntry, {
4
+ type: ProviderType;
5
+ }>;
3
6
  /**
4
7
  * Snippet providers don't synthesize tags (the user pastes the provider-issued
5
8
  * snippet as the entry's `body`), but they still get a first-class default
@@ -11,9 +14,7 @@ export declare function isXEventIdForPixel({ eventId, pixelId, }: {
11
14
  pixelId: string;
12
15
  }): boolean;
13
16
  /** The runtime injects these tags in order after consent allows tracking. */
14
- export declare function buildScriptTags(entry: Extract<ReploScriptEntry, {
15
- type: ProviderType;
16
- }>): ScriptTagDescriptor[];
17
+ export declare function buildScriptTags(entry: ProviderScriptEntry): ScriptTagDescriptor[];
17
18
  /**
18
19
  * The default consent categories that gate an identifier-provider script when an
19
20
  * entry does not specify `requiredConsent`. `snippet` and `custom` entries carry
@@ -1,3 +1,12 @@
1
+ const MIXPANEL_API_HOSTS = {
2
+ us: null,
3
+ eu: "https://api-eu.mixpanel.com",
4
+ in: "https://api-in.mixpanel.com"
5
+ };
6
+ function mixpanelInitOptions(region) {
7
+ const apiHost = MIXPANEL_API_HOSTS[region ?? "us"];
8
+ return apiHost ? `{track_pageview:false,api_host:${JSON.stringify(apiHost)}}` : "{track_pageview:false}";
9
+ }
1
10
  const PROVIDER_SNIPPETS = {
2
11
  GA4: {
3
12
  defaultConsent: ["analytics"],
@@ -138,6 +147,15 @@ gtag('config', '${id}');`
138
147
  }
139
148
  ]
140
149
  },
150
+ Mixpanel: {
151
+ defaultConsent: ["analytics"],
152
+ buildTags: (id, entry) => [
153
+ {
154
+ kind: "inline",
155
+ body: `(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){var e=arguments;a.push([f,[c].concat(Array.prototype.slice.call(e,0))])}}for(var d={},f=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f.head.appendChild(e)}})(document,window.mixpanel||[]);mixpanel.init("${id}",${mixpanelInitOptions(entry.type === "Mixpanel" ? entry.region : void 0)});mixpanel.track("Page Viewed",{url:location.href,path:location.pathname,title:document.title||undefined,referrer:document.referrer||undefined,navigation_type:"initial"});`
156
+ }
157
+ ]
158
+ },
141
159
  Gorgias: {
142
160
  defaultConsent: ["preferences"],
143
161
  buildTags: (id) => [
@@ -167,7 +185,7 @@ function isXEventIdForPixel({
167
185
  return match?.[1]?.toLowerCase() === pixelId.toLowerCase();
168
186
  }
169
187
  function buildScriptTags(entry) {
170
- const tags = PROVIDER_SNIPPETS[entry.type].buildTags(entry.identifier);
188
+ const tags = PROVIDER_SNIPPETS[entry.type].buildTags(entry.identifier, entry);
171
189
  if (entry.type === "X") {
172
190
  const pageViewId = entry.events?.pageView?.trim();
173
191
  if (pageViewId && isXEventIdForPixel({ eventId: pageViewId, pixelId: entry.identifier })) {
@@ -1,4 +1,4 @@
1
- export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "X" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "HubSpot" | "Cookiebot" | "snippet" | "custom" | "consentPlatform";
1
+ export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "X" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "HubSpot" | "Mixpanel" | "Cookiebot" | "snippet" | "custom" | "consentPlatform";
2
2
  export type ConsentCategory = "necessary" | "analytics" | "marketing" | "preferences" | "sale_of_data";
3
3
  export type ConsentMode = "off" | "simple" | "per-category";
4
4
  declare module "react" {
@@ -23,6 +23,7 @@ export type XPixelEvents = {
23
23
  startCheckout?: string;
24
24
  purchase?: string;
25
25
  };
26
+ export type MixpanelRegion = "us" | "eu" | "in";
26
27
  export type ReploScriptEntry = {
27
28
  type: "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "Hotjar" | "MicrosoftClarity" | "Contentsquare" | "Segment" | "Northbeam" | "Gorgias" | "Converge" | "HubSpot" | "Cookiebot";
28
29
  identifier: string;
@@ -32,6 +33,11 @@ export type ReploScriptEntry = {
32
33
  identifier: string;
33
34
  events?: XPixelEvents;
34
35
  requiredConsent?: ConsentCategory[];
36
+ } | {
37
+ type: "Mixpanel";
38
+ identifier: string;
39
+ region?: MixpanelRegion;
40
+ requiredConsent?: ConsentCategory[];
35
41
  } | {
36
42
  type: "snippet";
37
43
  id: string;
@@ -1,7 +1,7 @@
1
1
  export const BUILD_METADATA = {
2
2
  "packageName": "@replohq/sdk",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "branch": "HEAD",
5
- "commit": "fd5e2e68393795f73c76f04e5fbccad127d8ee31",
6
- "builtAt": "2026-10-20T14:39:29.462Z"
5
+ "commit": "425a057ac5f569a875e63976fa5a936dc651e292",
6
+ "builtAt": "2026-10-20T23:04:33.045Z"
7
7
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@replohq/sdk",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "reploBuild": {
5
5
  "packageName": "@replohq/sdk",
6
- "version": "2.1.0",
6
+ "version": "2.2.0",
7
7
  "branch": "HEAD",
8
- "commit": "fd5e2e68393795f73c76f04e5fbccad127d8ee31",
9
- "builtAt": "2026-10-20T14:39:29.462Z"
8
+ "commit": "425a057ac5f569a875e63976fa5a936dc651e292",
9
+ "builtAt": "2026-10-20T23:04:33.045Z"
10
10
  },
11
11
  "description": "Replo SDK — cart, analytics, and data loaders for agent-built Next.js sites.",
12
12
  "license": "SEE LICENSE IN LICENSE",