Expected Behavior
When configuring the SDK with autocapture.attribution settings, UTM parameters and other marketing
attribution data should be automatically tracked according to the documentation at
https://amplitude.com/docs/sdks/analytics/browser/browser-sdk-2
amplitude.init(apiKey, undefined, {
autocapture: {
attribution: {
resetSessionOnNewCampaign: true,
},
},
});
This should capture UTM parameters (utm_source, utm_medium, etc.), referrer data, and click IDs when users visit with campaign parameters.
Current Behavior
Attribution tracking silently fails when configured using only the autocapture property. UTM parameters are not captured, and no attribution events are sent to Amplitude.
The only way to get attribution working is to either:
- Use the deprecated
@amplitude/plugin-web-attribution-browser plugin, OR
- Set both
autocapture AND the deprecated defaultTracking property to the same configuration
Possible Solution
The SDK has an inconsistency where some autocapture features check config.autocapture (correct) while others check the deprecated config.defaultTracking (incorrect).
Files that need to be fixed:
packages/analytics-browser/src/browser-client.ts - Update these lines to use this.config.autocapture
instead of this.config.defaultTracking:
- Line 172: Attribution tracking check
- Line 224: File download tracking check
- Line 229: Form interaction tracking check
- Line 235: Page view tracking check
- Lines 361, 381: Session tracking checks
packages/analytics-browser/src/default-tracking.ts - Update these functions:
- Lines 227-241:
getAttributionTrackingConfig() should check config.autocapture instead of
config.defaultTracking
- Lines 188-225:
getPageViewTrackingConfig() should check config.autocapture instead of
config.defaultTracking
Note: Commit 97969c3 on branch AMP-125616/refactor-sr-observer-to-use-network-observer already partially fixed this issue for network tracking but was never completed or merged.
Steps to Reproduce
- Initialize the SDK with autocapture attribution enabled:
import * as amplitude from '@amplitude/analytics-browser';
amplitude.init('your-api-key', undefined, {
autocapture: {
attribution: {
resetSessionOnNewCampaign: true,
},
},
});
- Visit your application with UTM parameters:
https://yourapp.com?utm_source=test&utm_medium=email&utm_campaign=spring2024
- Check the Amplitude event stream for the user
- Observe: No UTM parameters are captured. Attribution tracking does not work.
- Workaround: Add defaultTracking with the same config:
const config = {
attribution: {
resetSessionOnNewCampaign: true,
},
};
amplitude.init('your-api-key', undefined, {
autocapture: config,
defaultTracking: config, // Required for attribution to work
});
- Repeat steps 2-3: Attribution now works correctly.
Environment
- JS SDK Version: @amplitude/analytics-browser 2.29.0 (issue exists in all 2.x versions)
- Installation Method: npm and yarn
- Browser and Version: all browsers
Expected Behavior
When configuring the SDK with
autocapture.attributionsettings, UTM parameters and other marketingattribution data should be automatically tracked according to the documentation at
https://amplitude.com/docs/sdks/analytics/browser/browser-sdk-2
This should capture UTM parameters (
utm_source,utm_medium, etc.), referrer data, and click IDs when users visit with campaign parameters.Current Behavior
Attribution tracking silently fails when configured using only the autocapture property. UTM parameters are not captured, and no attribution events are sent to Amplitude.
The only way to get attribution working is to either:
@amplitude/plugin-web-attribution-browserplugin, ORautocaptureAND the deprecateddefaultTrackingproperty to the same configurationPossible Solution
The SDK has an inconsistency where some
autocapturefeatures checkconfig.autocapture(correct) while others check the deprecatedconfig.defaultTracking(incorrect).Files that need to be fixed:
packages/analytics-browser/src/browser-client.ts- Update these lines to usethis.config.autocaptureinstead of
this.config.defaultTracking:packages/analytics-browser/src/default-tracking.ts- Update these functions:getAttributionTrackingConfig()should checkconfig.autocaptureinstead ofconfig.defaultTrackinggetPageViewTrackingConfig()should checkconfig.autocaptureinstead ofconfig.defaultTrackingNote: Commit 97969c3 on branch
AMP-125616/refactor-sr-observer-to-use-network-observeralready partially fixed this issue for network tracking but was never completed or merged.Steps to Reproduce
https://yourapp.com?utm_source=test&utm_medium=email&utm_campaign=spring2024Environment