Instrumenting Amplitude Session Replay with Google Tag Manager requires a different procedure than with the standard Browser SDK Plugin. To instrument Session Replay with Google Tag Manager:
Initialization
.Initialization
. 1<script> 2 function loadAsync(src, callback) { 3 var script = document.createElement('script'); 4 script.src = src; 5 if (script.readyState) { // IE, incl. IE9 6 script.onreadystatechange = function() { 7 if (script.readyState === "loaded" || script.readyState === "complete") { 8 script.onreadystatechange = null; 9 callback();10 }11 };12 } else {13 script.onload = function() { // Other browsers14 callback();15 };16 }17 document.getElementsByTagName('head')[0].appendChild(script);18 }19 20 loadAsync("https://cdn.amplitude.com/libs/plugin-session-replay-browser-1.8.1-min.js.gz",21 function () {22 var sessionReplayTracking = window.sessionReplay.plugin({sampleRate: 1});23 window.amplitude.add(sessionReplayTracking).promise;24 });25 26</script>
The sample rate in this sample is set to 1, or 100%, which means every session is captured. This is good for testing, but not recommended for production. For more information, see Session Replay Plugin | Sample Rate.
Multiple instantiation of the Amplitude SDKs. This is a common problem seen with GTM and other code injection frameworks. Ensure that the initialization logic is only run once on your app. This could happen if:
This template uses the Amplitude Browser SDK Plugin. For help troubleshooting, see Troubleshooting | Session Replay Plugin
Thanks for your feedback!
September 19th, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.