@tagadapay/plugin-sdk 2.3.2 → 2.3.3

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,6 +1,7 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { useCurrency } from '../hooks/useCurrency';
3
3
  import { useTagadaContext } from '../providers/TagadaProvider';
4
+ import { collectTrackingData } from '../utils/trackingUtils';
4
5
  import { usePluginConfig } from './usePluginConfig';
5
6
  export function useCheckout(options = {}) {
6
7
  const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = useTagadaContext();
@@ -77,9 +78,13 @@ export function useCheckout(options = {}) {
77
78
  setIsLoading(true);
78
79
  setError(null);
79
80
  try {
80
- // Enhanced customerMetadata without tracking data
81
+ // Collect tracking data
82
+ const trackingData = await collectTrackingData();
83
+ // Enhanced customerMetadata with tracking data
81
84
  const enhancedCustomerMetadata = {
82
85
  ...params.customerMetadata,
86
+ localStorage: trackingData.localStorageData,
87
+ cookies: trackingData.trackingCookiesData,
83
88
  };
84
89
  const requestBody = {
85
90
  ...params,
@@ -0,0 +1,24 @@
1
+ export interface TrackingData {
2
+ trackingCookiesData: Record<string, string>;
3
+ localStorageData: Record<string, string>;
4
+ }
5
+ /**
6
+ * Define pixel tracking cookie patterns for various platforms
7
+ */
8
+ export declare const trackingCookiePatterns: RegExp[];
9
+ /**
10
+ * Function to get cookies with retry logic
11
+ */
12
+ export declare const getCookiesWithRetry: (maxRetries?: number, delay?: number) => Promise<string[]>;
13
+ /**
14
+ * Collect localStorage data as dictionary
15
+ */
16
+ export declare const getLocalStorageData: () => Record<string, string>;
17
+ /**
18
+ * Collect tracking cookies data based on defined patterns
19
+ */
20
+ export declare const getTrackingCookiesData: () => Promise<Record<string, string>>;
21
+ /**
22
+ * Collect all tracking data (localStorage and cookies)
23
+ */
24
+ export declare const collectTrackingData: () => Promise<TrackingData>;
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Define pixel tracking cookie patterns for various platforms
3
+ */
4
+ export const trackingCookiePatterns = [
5
+ // Meta/Facebook pixels
6
+ /^_fbp/,
7
+ /^_fbc/,
8
+ /^fr$/,
9
+ /^_fbq/,
10
+ /^fbq/,
11
+ /^sb$/,
12
+ // Google Analytics & Ads
13
+ /^_ga/,
14
+ /^_gid/,
15
+ /^_gcl_au/,
16
+ /^_gac_/,
17
+ /^_gtag/,
18
+ /^_gat/,
19
+ /^_dc_gtm_/,
20
+ /^_gtm/,
21
+ // Google Ads
22
+ /^_gcl_/,
23
+ /^_gclid/,
24
+ /^_gclsrc/,
25
+ // Snapchat
26
+ /^_scid/,
27
+ /^_sctr/,
28
+ /^_schn/,
29
+ /^_scpx/,
30
+ // TikTok
31
+ /^_ttp/,
32
+ /^_tt_enable_cookie/,
33
+ /^_ttclid/,
34
+ /^_tta/,
35
+ // Pinterest
36
+ /^_pin/,
37
+ /^_pinterest_/,
38
+ /^_pinid/,
39
+ // Twitter/X
40
+ /^_twitter/,
41
+ /^_twid/,
42
+ /^muc_ads/,
43
+ // LinkedIn
44
+ /^_li/,
45
+ /^AnalyticsSyncHistory/,
46
+ /^bcookie/,
47
+ /^bscookie/,
48
+ // Microsoft/Bing
49
+ /^_uetsid/,
50
+ /^_uetvid/,
51
+ /^MUID/,
52
+ /^_msdcs/,
53
+ // Amazon
54
+ /^ad-id/,
55
+ /^ad-privacy/,
56
+ // CVG tracking
57
+ /^__cvg_uid/,
58
+ /^__cvg_sid/,
59
+ /^__cvg_session/,
60
+ // Shopify tracking
61
+ /^_shopify_y/,
62
+ /^_shopify_s/,
63
+ /^_shopify_ga/,
64
+ /^_shopify_ga_/,
65
+ /^_shopify_sa_p/,
66
+ /^_shopify_sa_t/,
67
+ // General tracking
68
+ /^_awc/,
69
+ /^_aw_/,
70
+ /^utm_/,
71
+ /^_clck/,
72
+ /^_clsk/,
73
+ ];
74
+ /**
75
+ * Function to get cookies with retry logic
76
+ */
77
+ export const getCookiesWithRetry = async (maxRetries = 3, delay = 100) => {
78
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
79
+ try {
80
+ const cookies = document.cookie.split('; ');
81
+ if (cookies.length > 0 && cookies[0] !== '') {
82
+ return cookies;
83
+ }
84
+ // If no cookies found, wait and retry
85
+ if (attempt < maxRetries) {
86
+ console.log(`Cookie collection attempt ${attempt} failed, retrying in ${delay}ms...`);
87
+ await new Promise((resolve) => setTimeout(resolve, delay));
88
+ }
89
+ }
90
+ catch (error) {
91
+ console.warn(`Cookie collection attempt ${attempt} failed:`, error);
92
+ if (attempt < maxRetries) {
93
+ await new Promise((resolve) => setTimeout(resolve, delay));
94
+ }
95
+ }
96
+ }
97
+ return [];
98
+ };
99
+ /**
100
+ * Collect localStorage data as dictionary
101
+ */
102
+ export const getLocalStorageData = () => {
103
+ const localStorageData = {};
104
+ try {
105
+ for (let i = 0; i < localStorage.length; i++) {
106
+ const key = localStorage.key(i);
107
+ if (key) {
108
+ localStorageData[key] = localStorage.getItem(key) || '';
109
+ }
110
+ }
111
+ }
112
+ catch (error) {
113
+ console.warn('Failed to read localStorage:', error);
114
+ }
115
+ return localStorageData;
116
+ };
117
+ /**
118
+ * Collect tracking cookies data based on defined patterns
119
+ */
120
+ export const getTrackingCookiesData = async () => {
121
+ const trackingCookiesData = {};
122
+ try {
123
+ // Get cookies with retry logic
124
+ const cookies = await getCookiesWithRetry();
125
+ if (cookies.length === 0) {
126
+ console.warn('No cookies found after retry attempts');
127
+ }
128
+ else {
129
+ console.log(`Successfully collected ${cookies.length} cookies`);
130
+ }
131
+ cookies.forEach((cookie) => {
132
+ const [key, ...valueParts] = cookie.split('=');
133
+ const value = valueParts.join('='); // Handle values that might contain =
134
+ if (key && trackingCookiePatterns.some((pattern) => pattern.test(key))) {
135
+ try {
136
+ trackingCookiesData[key] = decodeURIComponent(value || '');
137
+ }
138
+ catch (error) {
139
+ // If decoding fails, use raw value
140
+ trackingCookiesData[key] = value || '';
141
+ }
142
+ }
143
+ });
144
+ // Log specific cookies we're looking for
145
+ const importantCookies = ['_shopify_y', '__cvg_uid', '_fbp', '_ga'];
146
+ importantCookies.forEach((cookieName) => {
147
+ if (trackingCookiesData[cookieName]) {
148
+ console.log(`Found ${cookieName}:`, trackingCookiesData[cookieName]);
149
+ }
150
+ else {
151
+ console.log(`Missing ${cookieName} cookie`);
152
+ }
153
+ });
154
+ }
155
+ catch (error) {
156
+ console.warn('Failed to read tracking cookies:', error);
157
+ }
158
+ return trackingCookiesData;
159
+ };
160
+ /**
161
+ * Collect all tracking data (localStorage and cookies)
162
+ */
163
+ export const collectTrackingData = async () => {
164
+ const [localStorageData, trackingCookiesData] = await Promise.all([
165
+ Promise.resolve(getLocalStorageData()),
166
+ getTrackingCookiesData(),
167
+ ]);
168
+ return {
169
+ localStorageData,
170
+ trackingCookiesData,
171
+ };
172
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",