@tagadapay/plugin-sdk 3.1.12 → 3.1.24

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.
Files changed (144) hide show
  1. package/build-cdn.js +397 -11
  2. package/dist/data/iso3166.d.ts +23 -33
  3. package/dist/data/iso3166.js +134 -198
  4. package/dist/data/languages.d.ts +5 -64
  5. package/dist/data/languages.js +23 -143
  6. package/dist/external-tracker.js +623 -3426
  7. package/dist/external-tracker.min.js +2 -25
  8. package/dist/external-tracker.min.js.map +4 -4
  9. package/dist/react/config/payment.d.ts +14 -4
  10. package/dist/react/config/payment.js +47 -9
  11. package/dist/react/hooks/useCheckout.d.ts +3 -0
  12. package/dist/react/hooks/useCheckout.js +4 -1
  13. package/dist/react/hooks/useISOData.js +1 -1
  14. package/dist/react/hooks/usePaymentPolling.d.ts +3 -3
  15. package/dist/react/hooks/usePluginConfig.js +9 -10
  16. package/dist/react/providers/TagadaProvider.js +1 -1
  17. package/dist/tagada-react-sdk-minimal.min.js +36 -0
  18. package/dist/tagada-react-sdk-minimal.min.js.map +7 -0
  19. package/dist/tagada-react-sdk.js +37821 -0
  20. package/dist/tagada-react-sdk.min.js +78 -0
  21. package/dist/tagada-react-sdk.min.js.map +7 -0
  22. package/dist/tagada-sdk.js +16044 -0
  23. package/dist/tagada-sdk.min.js +32 -0
  24. package/dist/tagada-sdk.min.js.map +7 -0
  25. package/dist/v2/cdn-react-minimal.d.ts +23 -0
  26. package/dist/v2/cdn-react-minimal.js +26 -0
  27. package/dist/v2/core/client.d.ts +4 -2
  28. package/dist/v2/core/client.js +5 -4
  29. package/dist/v2/core/config/environment.js +2 -1
  30. package/dist/v2/core/errors.d.ts +75 -0
  31. package/dist/v2/core/errors.js +104 -0
  32. package/dist/v2/core/funnelClient.d.ts +100 -10
  33. package/dist/v2/core/funnelClient.js +121 -27
  34. package/dist/v2/core/isoData.d.ts +4 -4
  35. package/dist/v2/core/isoData.js +7 -7
  36. package/dist/v2/core/pixelMapping.d.ts +49 -0
  37. package/dist/v2/core/pixelMapping.js +363 -0
  38. package/dist/v2/core/resources/apiClient.d.ts +2 -0
  39. package/dist/v2/core/resources/apiClient.js +52 -9
  40. package/dist/v2/core/resources/checkout.d.ts +99 -30
  41. package/dist/v2/core/resources/checkout.js +14 -0
  42. package/dist/v2/core/resources/customer.d.ts +20 -19
  43. package/dist/v2/core/resources/expressPaymentMethods.d.ts +1 -0
  44. package/dist/v2/core/resources/funnel.d.ts +17 -17
  45. package/dist/v2/core/resources/payments.d.ts +89 -13
  46. package/dist/v2/core/resources/payments.js +27 -9
  47. package/dist/v2/core/resources/postPurchases.d.ts +17 -0
  48. package/dist/v2/core/resources/postPurchases.js +20 -0
  49. package/dist/v2/core/types.d.ts +50 -12
  50. package/dist/v2/core/types.js +0 -3
  51. package/dist/v2/core/utils/checkout.d.ts +2 -2
  52. package/dist/v2/core/utils/checkout.js +7 -2
  53. package/dist/v2/core/utils/currency.d.ts +14 -0
  54. package/dist/v2/core/utils/currency.js +40 -0
  55. package/dist/v2/core/utils/deviceInfo.d.ts +0 -10
  56. package/dist/v2/core/utils/deviceInfo.js +152 -76
  57. package/dist/v2/core/utils/index.d.ts +1 -0
  58. package/dist/v2/core/utils/index.js +2 -0
  59. package/dist/v2/core/utils/order.d.ts +13 -9
  60. package/dist/v2/core/utils/pluginConfig.d.ts +8 -0
  61. package/dist/v2/core/utils/pluginConfig.js +36 -12
  62. package/dist/v2/index.d.ts +6 -3
  63. package/dist/v2/index.js +4 -2
  64. package/dist/v2/react/components/FunnelScriptInjector.js +166 -77
  65. package/dist/v2/react/components/StripeExpressButton.d.ts +13 -0
  66. package/dist/v2/react/components/StripeExpressButton.js +171 -0
  67. package/dist/v2/react/components/WhopCheckout.d.ts +24 -0
  68. package/dist/v2/react/components/WhopCheckout.js +237 -0
  69. package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +1 -1
  70. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.d.ts +14 -0
  71. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.js +181 -0
  72. package/dist/v2/react/hooks/payment-actions/useErrorAction.d.ts +9 -0
  73. package/dist/v2/react/hooks/payment-actions/useErrorAction.js +21 -0
  74. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.d.ts +14 -0
  75. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.js +187 -0
  76. package/dist/v2/react/hooks/payment-actions/useKessPayAction.d.ts +11 -0
  77. package/dist/v2/react/hooks/payment-actions/useKessPayAction.js +91 -0
  78. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.d.ts +24 -0
  79. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.js +221 -0
  80. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.d.ts +15 -0
  81. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.js +142 -0
  82. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.d.ts +3 -0
  83. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.js +31 -0
  84. package/dist/v2/react/hooks/payment-actions/useRedirectAction.d.ts +10 -0
  85. package/dist/v2/react/hooks/payment-actions/useRedirectAction.js +35 -0
  86. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.d.ts +14 -0
  87. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.js +192 -0
  88. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.d.ts +14 -0
  89. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.js +81 -0
  90. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.d.ts +11 -0
  91. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.js +84 -0
  92. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.d.ts +14 -0
  93. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.js +36 -0
  94. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.d.ts +31 -0
  95. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.js +212 -0
  96. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.d.ts +14 -0
  97. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.js +207 -0
  98. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.d.ts +12 -0
  99. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.js +101 -0
  100. package/dist/v2/react/hooks/useApplePayCheckout.js +8 -8
  101. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +16 -0
  102. package/dist/v2/react/hooks/useCheckoutQuery.js +63 -10
  103. package/dist/v2/react/hooks/useFunnel.d.ts +15 -4
  104. package/dist/v2/react/hooks/useFunnel.js +8 -4
  105. package/dist/v2/react/hooks/useGeoLocation.d.ts +2 -1
  106. package/dist/v2/react/hooks/useGeoLocation.js +4 -2
  107. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +2 -0
  108. package/dist/v2/react/hooks/useGoogleAutocomplete.js +29 -15
  109. package/dist/v2/react/hooks/useISOData.d.ts +2 -5
  110. package/dist/v2/react/hooks/useISOData.js +26 -27
  111. package/dist/v2/react/hooks/usePaymentPolling.d.ts +3 -3
  112. package/dist/v2/react/hooks/usePaymentQuery.d.ts +18 -5
  113. package/dist/v2/react/hooks/usePaymentQuery.js +63 -1015
  114. package/dist/v2/react/hooks/usePaymentRetrieve.d.ts +3 -2
  115. package/dist/v2/react/hooks/usePaymentRetrieve.js +3 -1
  116. package/dist/v2/react/hooks/usePixelTracking.d.ts +5 -48
  117. package/dist/v2/react/hooks/usePixelTracking.js +283 -504
  118. package/dist/v2/react/hooks/usePostPurchasesQuery.js +34 -2
  119. package/dist/v2/react/hooks/useRemappableParams.d.ts +2 -6
  120. package/dist/v2/react/hooks/useRemappableParams.js +23 -23
  121. package/dist/v2/react/hooks/useSetPaymentMethod.d.ts +16 -0
  122. package/dist/v2/react/hooks/useSetPaymentMethod.js +33 -0
  123. package/dist/v2/react/hooks/useShippingRatesQuery.js +13 -5
  124. package/dist/v2/react/hooks/useStepConfig.d.ts +23 -6
  125. package/dist/v2/react/hooks/useStepConfig.js +14 -7
  126. package/dist/v2/react/hooks/useTranslation.js +23 -8
  127. package/dist/v2/react/hooks/useWhopPaymentPolling.d.ts +30 -0
  128. package/dist/v2/react/hooks/useWhopPaymentPolling.js +61 -0
  129. package/dist/v2/react/index.d.ts +15 -1
  130. package/dist/v2/react/index.js +7 -0
  131. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +3 -1
  132. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +12 -2
  133. package/dist/v2/react/providers/TagadaProvider.js +74 -5
  134. package/dist/v2/standalone/external-tracker.d.ts +52 -46
  135. package/dist/v2/standalone/external-tracker.js +205 -98
  136. package/dist/v2/standalone/index.d.ts +40 -0
  137. package/dist/v2/standalone/index.js +148 -1
  138. package/dist/v2/standalone/payment-service.d.ts +134 -0
  139. package/dist/v2/standalone/payment-service.js +928 -0
  140. package/package.json +6 -4
  141. package/dist/react/utils/__tests__/urlUtils.test.d.ts +0 -1
  142. package/dist/react/utils/__tests__/urlUtils.test.js +0 -189
  143. package/dist/v2/core/__tests__/pathRemapping.test.d.ts +0 -11
  144. package/dist/v2/core/__tests__/pathRemapping.test.js +0 -776
@@ -3,6 +3,7 @@
3
3
  * Manages express payment methods (Apple Pay, Google Pay, PayPal, Klarna)
4
4
  */
5
5
  import React, { ReactNode } from 'react';
6
+ import { TagadaError } from '../../core/errors';
6
7
  import { CheckoutData } from '../../core/resources/checkout';
7
8
  import { Address, PaymentMethod } from '../../core/resources/expressPaymentMethods';
8
9
  type ExpressOrderLineItem = {
@@ -21,6 +22,7 @@ interface ExpressPaymentMethodsContextType {
21
22
  googlePayPaymentMethod?: PaymentMethod;
22
23
  paypalPaymentMethod?: PaymentMethod;
23
24
  klarnaPaymentMethod?: PaymentMethod;
25
+ stripeExpressPaymentMethod?: PaymentMethod;
24
26
  availableExpressPaymentMethodIds: string[];
25
27
  setAvailableExpressPaymentMethodIds: (value: string[]) => void;
26
28
  handleAddExpressId: (id: string) => void;
@@ -47,7 +49,7 @@ interface ExpressPaymentMethodsContextType {
47
49
  };
48
50
  }) => Promise<void>;
49
51
  loading?: boolean;
50
- error: string | null;
52
+ error: TagadaError | null;
51
53
  setError: (error: string | null) => void;
52
54
  }
53
55
  interface ExpressPaymentMethodsProviderProps {
@@ -5,6 +5,7 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
5
5
  */
6
6
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
7
7
  import { createContext, useCallback, useMemo, useState } from 'react';
8
+ import { TagadaError, TagadaErrorCode } from '../../core/errors';
8
9
  import { ExpressPaymentMethodsResource, } from '../../core/resources/expressPaymentMethods';
9
10
  import { getGlobalApiClient } from '../hooks/useApiQuery';
10
11
  import { useShippingRatesQuery } from '../hooks/useShippingRatesQuery';
@@ -169,7 +170,15 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
169
170
  const googlePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'google_pay'), [paymentMethods]);
170
171
  const paypalPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'paypal'), [paymentMethods]);
171
172
  const klarnaPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'klarna'), [paymentMethods]);
173
+ // Find a stripe_apm or tagadapay_apm integration with any express method enabled in any processor group.
174
+ // Backward compatible: existing configs with only apple_pay/google_pay continue to match.
175
+ const stripeExpressPaymentMethod = useMemo(() => {
176
+ const EXPRESS_METHOD_KEYS = ['apple_pay', 'google_pay', 'paypal', 'link', 'klarna_express'];
177
+ return paymentMethods?.find((p) => (p.type === 'stripe_apm' || p.type === 'tagadapay_apm') &&
178
+ p.settings?.processors?.some((g) => EXPRESS_METHOD_KEYS.some((key) => g?.methods?.[key]?.enabled === true)));
179
+ }, [paymentMethods]);
172
180
  const loading = !paymentMethods || isLoadingPaymentMethods;
181
+ const tagadaError = useMemo(() => error ? new TagadaError(error, { code: TagadaErrorCode.PAYMENT_FAILED }) : null, [error]);
173
182
  const contextValue = {
174
183
  paymentMethods,
175
184
  availableExpressPaymentMethodIds,
@@ -178,6 +187,7 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
178
187
  googlePayPaymentMethod,
179
188
  paypalPaymentMethod,
180
189
  klarnaPaymentMethod,
190
+ stripeExpressPaymentMethod,
181
191
  shippingMethods,
182
192
  lineItems,
183
193
  reComputeOrderSummary,
@@ -185,9 +195,9 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
185
195
  handleAddExpressId,
186
196
  updateCheckoutSessionValues,
187
197
  updateCustomerEmail,
188
- error,
198
+ error: tagadaError,
189
199
  setError,
190
200
  };
191
- const hasAnyEnabled = Boolean(applePayPaymentMethod || googlePayPaymentMethod || paypalPaymentMethod || klarnaPaymentMethod);
201
+ const hasAnyEnabled = Boolean(applePayPaymentMethod || googlePayPaymentMethod || paypalPaymentMethod || klarnaPaymentMethod || stripeExpressPaymentMethod);
192
202
  return (_jsx(ExpressPaymentMethodsContext.Provider, { value: contextValue, children: hasAnyEnabled ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, {}) }));
193
203
  };
@@ -4,14 +4,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
4
4
  * TagadaProvider - Main provider component for the Tagada Pay React SDK
5
5
  */
6
6
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
7
- import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
7
+ import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useState } from 'react';
8
8
  import { ApiService } from '../../../react/services/apiService';
9
9
  import { convertCurrency, formatMoney, formatMoneyWithoutSymbol, formatSimpleMoney, getCurrencyInfo, minorUnitsToMajorUnits, moneyStringOrNumberToMinorUnits, } from '../../../react/utils/money';
10
10
  import { TagadaClient } from '../../core/client';
11
- import { default as DebugDrawer } from '../components/DebugDrawer';
12
- import { FunnelScriptInjector } from '../components/FunnelScriptInjector';
13
11
  import { setGlobalApiClient } from '../hooks/useApiQuery';
14
12
  import { PixelTrackingProvider } from '../hooks/usePixelTracking';
13
+ const FunnelScriptInjector = lazy(() => import('../components/FunnelScriptInjector').then(m => ({ default: m.FunnelScriptInjector })));
14
+ const DebugDrawer = lazy(() => import('../components/DebugDrawer'));
15
15
  // Professional, subtle loading component for initialization
16
16
  const InitializationLoader = () => (_jsxs("div", { style: {
17
17
  position: 'fixed',
@@ -213,6 +213,75 @@ export function TagadaProvider({ children, environment, customApiConfig, debugMo
213
213
  formatSimpleMoney,
214
214
  }), []);
215
215
  const [isDebugDrawerOpen, setIsDebugDrawerOpen] = useState(false);
216
+ // Track last injected script to prevent duplicate execution
217
+ /**
218
+ * Editor Element Click Bridge (Iframe → Parent)
219
+ *
220
+ * When running inside the CRM config editor iframe, elements can declare an `editor-id`
221
+ * attribute (e.g. <h1 editor-id="config.texts.checkoutTitle">Title</h1>).
222
+ *
223
+ * This effect sets up a delegated click listener on `document` that:
224
+ * - Finds the closest ancestor with an `editor-id`
225
+ * - Sends a `postMessage` to `window.parent` with the editorId and text content
226
+ *
227
+ * The parent (ConfigEditor) can then map this back to the corresponding config field.
228
+ */
229
+ useEffect(() => {
230
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
231
+ return;
232
+ }
233
+ const handleClick = (event) => {
234
+ if (!(event.target instanceof Element))
235
+ return;
236
+ const targetWithEditorId = event.target.closest('[editor-id]');
237
+ if (!targetWithEditorId)
238
+ return;
239
+ const editorId = targetWithEditorId.getAttribute('editor-id');
240
+ if (!editorId)
241
+ return;
242
+ const textContent = targetWithEditorId.textContent ?? '';
243
+ // Only attempt cross-window messaging when inside an iframe
244
+ const isInIframe = window.parent && window.parent !== window;
245
+ if (!isInIframe) {
246
+ return;
247
+ }
248
+ const message = {
249
+ type: 'TAGADAPAY_EDITOR_ELEMENT_CLICK',
250
+ editorId,
251
+ textContent,
252
+ };
253
+ try {
254
+ // Derive parent origin from document.referrer when possible; fall back to '*'
255
+ // This avoids postMessage origin mismatch errors in dev (e.g. 3001 ↔ 5173)
256
+ let targetOrigin = '*';
257
+ try {
258
+ if (typeof document !== 'undefined' && document.referrer) {
259
+ const url = new URL(document.referrer);
260
+ targetOrigin = url.origin;
261
+ }
262
+ }
263
+ catch {
264
+ // Fallback to '*'
265
+ targetOrigin = '*';
266
+ }
267
+ window.parent.postMessage(message, targetOrigin);
268
+ if (state.debugMode) {
269
+ // eslint-disable-next-line no-console
270
+ console.log('[TagadaProvider] Sent editor element click to parent:', message);
271
+ }
272
+ }
273
+ catch (error) {
274
+ if (state.debugMode) {
275
+ // eslint-disable-next-line no-console
276
+ console.error('[TagadaProvider] Failed to post editor element click message:', error);
277
+ }
278
+ }
279
+ };
280
+ document.addEventListener('click', handleClick, true);
281
+ return () => {
282
+ document.removeEventListener('click', handleClick, true);
283
+ };
284
+ }, [state.debugMode]);
216
285
  // Funnel Methods
217
286
  const funnelMethods = useMemo(() => {
218
287
  if (!client.funnel) {
@@ -320,7 +389,7 @@ export function TagadaProvider({ children, environment, customApiConfig, debugMo
320
389
  // Loading State Logic
321
390
  const shouldShowLoading = state.isLoading || state.pluginConfigLoading || (blockUntilSessionReady && !state.isSessionInitialized);
322
391
  const canRenderChildren = !state.pluginConfigLoading && (!blockUntilSessionReady || state.isSessionInitialized);
323
- return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(TagadaContext.Provider, { value: contextValue, children: _jsxs(PixelTrackingProvider, { children: [_jsx(FunnelScriptInjector, { ...funnelState }), shouldShowLoading && _jsx(InitializationLoader, {}), state.debugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
392
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(TagadaContext.Provider, { value: contextValue, children: _jsxs(PixelTrackingProvider, { children: [_jsx(Suspense, { fallback: null, children: _jsx(FunnelScriptInjector, { ...funnelState }) }), shouldShowLoading && _jsx(InitializationLoader, {}), state.debugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
324
393
  position: 'fixed',
325
394
  bottom: '16px',
326
395
  right: '16px',
@@ -335,7 +404,7 @@ export function TagadaProvider({ children, environment, customApiConfig, debugMo
335
404
  boxShadow: '0 4px 12px rgba(0, 0, 0, 0.3)',
336
405
  zIndex: 999997,
337
406
  transition: 'all 0.2s ease',
338
- }, title: "Open TagadaPay SDK Debug Panel", children: "\uD83D\uDC1B" }), _jsx(DebugDrawer, { isOpen: isDebugDrawerOpen, onClose: () => setIsDebugDrawerOpen(false) })] })), canRenderChildren && children] }) }) }));
407
+ }, title: "Open TagadaPay SDK Debug Panel", children: "\uD83D\uDC1B" }), _jsx(Suspense, { fallback: null, children: _jsx(DebugDrawer, { isOpen: isDebugDrawerOpen, onClose: () => setIsDebugDrawerOpen(false) }) })] })), canRenderChildren && children] }) }) }));
339
408
  }
340
409
  export function useTagadaContext() {
341
410
  const context = useContext(TagadaContext);
@@ -1,59 +1,48 @@
1
1
  /**
2
2
  * TagadaPay External Page Tracker
3
3
  *
4
- * A lightweight standalone script for tracking users on external pages
5
- * that are part of a Tagadapay funnel but not hosted on the Tagadapay platform.
4
+ * Standalone script for tracking users on external pages that are part of a
5
+ * TagadaPay funnel but not hosted on the TagadaPay platform.
6
6
  *
7
- * ARCHITECTURE:
8
- * - Reuses core SDK infrastructure (TagadaClient) for authentication and API handling
9
- * - All tracking handled automatically by funnelOrchestrator via autoInitialize() and navigate()
10
- * - No separate tracking endpoints needed - unified tracking through orchestrator
7
+ * Use cases:
8
+ * - WooCommerce / WordPress storefronts
9
+ * - Custom landing pages
10
+ * - Any external page that is a funnel step
11
11
  *
12
- * Usage (via CDN):
12
+ * @example CDN usage
13
+ * ```html
13
14
  * <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/external-tracker.min.js"></script>
14
15
  * <script>
15
16
  * TagadaTracker.init({
16
17
  * storeId: 'store_xxx',
17
18
  * accountId: 'acc_xxx',
18
- * funnelId: 'funnel_xxx', // Optional: detected from URL
19
19
  * stepId: 'step_xxx',
20
- * stepName: 'External Offer Page',
21
- * stepType: 'external'
22
- * });
23
- *
24
- * // Navigate to next step (tracking automatic)
25
- * TagadaTracker.navigate({
26
- * eventType: 'form.submitted',
27
- * eventData: { email: 'user@example.com' }
28
20
  * });
29
21
  * </script>
22
+ * ```
30
23
  */
31
24
  import type { TagadaClient } from '../core/client';
25
+ export declare const TRACKER_VERSION = "1.0.0";
32
26
  export interface TagadaTrackerConfig {
33
27
  /** Store ID (required) */
34
28
  storeId: string;
35
- /** Account ID (required for session init) */
36
- accountId?: string;
37
- /** Funnel ID (optional - can be extracted from URL param) */
29
+ /** Account ID (required session init will fail without it) */
30
+ accountId: string;
31
+ /** Funnel ID (optional can be extracted from URL param) */
38
32
  funnelId?: string;
39
- /**
40
- * Step ID (REQUIRED for external pages)
41
- *
42
- * External URLs cannot be mapped to steps via URL matching (only works for Tagadapay-hosted pages).
43
- * You must explicitly specify which step this external page represents.
44
- */
33
+ /** Step ID (required for external pages — URL-to-step mapping only works for TagadaPay-hosted pages) */
45
34
  stepId: string;
46
- /** Step name (optional - for analytics/debugging) */
35
+ /** Step name (optional for analytics/debugging) */
47
36
  stepName?: string;
48
- /** Step type (optional - e.g., 'landing', 'offer', 'external') */
37
+ /** Step type (optional e.g., 'landing', 'offer', 'external') */
49
38
  stepType?: string;
50
- /** API base URL (defaults to production) */
39
+ /** API base URL (defaults to https://app.tagadapay.com) */
51
40
  apiBaseUrl?: string;
52
41
  /** Enable debug logging */
53
42
  debug?: boolean;
54
43
  /** Callback when session is ready */
55
44
  onReady?: (session: ExternalTrackerSession) => void;
56
- /** Callback on error */
45
+ /** Callback on error — when provided, init() will NOT throw */
57
46
  onError?: (error: Error) => void;
58
47
  }
59
48
  export interface ExternalTrackerSession {
@@ -71,49 +60,66 @@ export interface NavigateOptions {
71
60
  eventData?: Record<string, unknown>;
72
61
  /** Override return URL */
73
62
  returnUrl?: string;
74
- /** Disable auto-redirect to control navigation manually (default: true) */
63
+ /** Whether to auto-redirect after navigation (default: true) */
75
64
  autoRedirect?: boolean;
76
65
  }
66
+ export interface TrackEventOptions {
67
+ /** Event name (e.g., 'button_click', 'scroll_depth', 'video_play') */
68
+ name: string;
69
+ /** Arbitrary event data */
70
+ data?: Record<string, unknown>;
71
+ }
77
72
  declare class TagadaExternalTracker {
78
73
  private config;
79
74
  private client;
80
75
  private initialized;
81
76
  private initializing;
77
+ private unsubscribe;
78
+ /** Tracker version */
79
+ readonly version = "1.0.0";
82
80
  /**
83
- * Initialize the tracker using SDK infrastructure
81
+ * Initialize the tracker.
82
+ * When `onError` is provided, errors are passed to the callback and init()
83
+ * resolves to `null` instead of throwing.
84
84
  */
85
85
  init(config: TagadaTrackerConfig): Promise<ExternalTrackerSession | null>;
86
- /**
87
- * Get current session from SDK state
88
- */
86
+ /** Get current session data. */
89
87
  getSession(): ExternalTrackerSession | null;
90
- /**
91
- * Check if tracker is ready
92
- */
88
+ /** Whether the tracker is fully initialized and ready. */
93
89
  isReady(): boolean;
94
90
  /**
95
- * Navigate to next step in funnel using SDK's funnel client
91
+ * Navigate to the next step in the funnel.
92
+ * By default, auto-redirects the browser window.
96
93
  */
97
94
  navigate(options: NavigateOptions): Promise<{
98
95
  url: string;
99
96
  } | null>;
100
97
  /**
101
- * Get customer ID (for identifying the user)
98
+ * Track a custom event (e.g., button click, scroll depth, video play).
99
+ * Events are sent through the funnel orchestrator for unified analytics.
102
100
  */
101
+ trackEvent(options: TrackEventOptions): Promise<void>;
102
+ /** Get customer ID. */
103
103
  getCustomerId(): string | null;
104
- /**
105
- * Get funnel session ID
106
- */
104
+ /** Get funnel session ID. */
107
105
  getFunnelSessionId(): string | null;
108
106
  /**
109
- * Build a URL with funnel context parameters
110
- * Useful for linking to other external pages while preserving session
107
+ * Build a URL that preserves funnel session context.
108
+ * Use this to link to other external pages within the same funnel.
111
109
  */
112
110
  buildUrl(baseUrl: string, additionalParams?: Record<string, string>): string;
111
+ /** Get the underlying SDK client (advanced usage). */
112
+ getClient(): TagadaClient | null;
113
113
  /**
114
- * Get the underlying SDK client (for advanced usage)
114
+ * Reset the tracker to a new step without re-creating the session.
115
+ * Useful for SPAs that navigate between funnel steps client-side.
115
116
  */
116
- getClient(): TagadaClient | null;
117
+ reset(newStepId: string): Promise<ExternalTrackerSession | null>;
118
+ /**
119
+ * Destroy the tracker, clean up event listeners and state.
120
+ * Call this when the tracker is no longer needed (e.g., SPA teardown).
121
+ */
122
+ destroy(): void;
117
123
  private waitForClientReady;
118
124
  private initializeFunnel;
119
125
  }