@cascayd/experiment 0.3.18 → 0.3.19

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.
@@ -339,10 +339,10 @@
339
339
  }
340
340
 
341
341
  // Setup conversion tracking for an experiment
342
- function setupConversionTracking(experimentId) {
342
+ function setupConversionTracking(experimentId, sdk) {
343
343
  const selector = '[data-cascayd-experiment="' + experimentId + '"] [data-cascayd-conversion]';
344
344
  const elements = document.querySelectorAll(selector);
345
- console.log('[cascayd-shopify] 🎯 Setting up conversion tracking for experiment:', experimentId, 'found', elements.length, 'conversion elements');
345
+ console.log('[cascayd-shopify] 🎯 Setting up conversion tracking for experiment:', experimentId, 'found', elements.length, 'conversion elements', 'hasSDK:', !!sdk);
346
346
 
347
347
  elements.forEach(function(el) {
348
348
  // Skip if already tracked
@@ -358,16 +358,31 @@
358
358
  console.log('[cascayd-shopify] 🎯 Conversion click detected!');
359
359
  const variantId = findVariantIdFromElement(el, experimentId);
360
360
  if (variantId) {
361
- console.log('[cascayd-shopify] 📊 Recording conversion:', { experimentId, variantId });
362
- // Use direct API call since we're in standalone mode
363
- recordDirect('conversion', {
364
- experimentId: experimentId,
365
- variantId: variantId
366
- }).then(function() {
367
- console.log('[cascayd-shopify] ✅ Conversion recorded successfully');
368
- }).catch(function(error) {
369
- console.error('[cascayd-shopify] ❌ Failed to record conversion:', error);
370
- });
361
+ console.log('[cascayd-shopify] 📊 Recording conversion:', { experimentId, variantId, hasSDK: !!sdk, hasRecordFn: !!(sdk && sdk.record) });
362
+
363
+ // Use SDK's record function if available (same as impressions), otherwise fallback to direct API call
364
+ if (sdk && sdk.record) {
365
+ console.log('[cascayd-shopify] ✅ Using SDK record function for conversion');
366
+ sdk.record('conversion', {
367
+ experimentId: experimentId,
368
+ variantId: variantId
369
+ }).then(function() {
370
+ console.log('[cascayd-shopify] ✅ Conversion recorded successfully via SDK');
371
+ }).catch(function(error) {
372
+ console.error('[cascayd-shopify] ❌ Failed to record conversion via SDK:', error);
373
+ });
374
+ } else {
375
+ console.log('[cascayd-shopify] ⚠️ SDK record not available, using direct API call');
376
+ // Fallback to direct API call
377
+ recordDirect('conversion', {
378
+ experimentId: experimentId,
379
+ variantId: variantId
380
+ }).then(function() {
381
+ console.log('[cascayd-shopify] ✅ Conversion recorded successfully via direct API');
382
+ }).catch(function(error) {
383
+ console.error('[cascayd-shopify] ❌ Failed to record conversion via direct API:', error);
384
+ });
385
+ }
371
386
  } else {
372
387
  console.warn('[cascayd-shopify] ⚠️ No variant found for experiment', experimentId, 'when recording conversion');
373
388
  }
@@ -450,7 +465,7 @@
450
465
  });
451
466
 
452
467
  // Setup conversion tracking after variant is shown
453
- setupConversionTracking(experimentId);
468
+ setupConversionTracking(experimentId, sdk);
454
469
  console.log('[cascayd-shopify] ✅ Finished processing experiment:', experimentId);
455
470
  }
456
471
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascayd/experiment",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "description": "A lightweight A/B testing SDK for React applications with server-side analytics integration",
5
5
  "keywords": [
6
6
  "ab-testing",