So I’m not really sure what to do about this error.
I’m trying to instrument add to cart button click events to amplitude with this code:
<script type="text/javascript"><br /> document.addEventListener('DOMContentLoaded', function () {<br /> // Select all elements with the class 'sqs-add-to-cart-button'<br /> var addToCartButtons = document.querySelectorAll('.sqs-add-to-cart-button');<br /> // Attach click event listener to each button<br /> addToCartButtons.forEach(function(button) {<br /> button.addEventListener('click', function () {<br /> // Check if Amplitude is available and initialized<br /> var amplitudeInstance = amplitude.getInstance();<br /> if (amplitudeInstance) {<br /> // Log the event to Amplitude<br /> amplitudeInstance.logEvent('item_added_to_cart', { buttonId: button.id });<br /> } else {<br /> console.error('Amplitude not available or initialized.');<br /> }<br /> });<br /> });<br /> });<br /></script>
But it produces the problem that amplitude.getinstance is not a function. Could anyone give me some guidance?