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">
document.addEventListener('DOMContentLoaded', function () {
// Select all elements with the class 'sqs-add-to-cart-button'
var addToCartButtons = document.querySelectorAll('.sqs-add-to-cart-button');
// Attach click event listener to each button
addToCartButtons.forEach(function(button) {
button.addEventListener('click', function () {
// Check if Amplitude is available and initialized
var amplitudeInstance = amplitude.getInstance();
if (amplitudeInstance) {
// Log the event to Amplitude
amplitudeInstance.logEvent('item_added_to_cart', { buttonId: button.id });
} else {
console.error('Amplitude not available or initialized.');
}
});
});
});
</script>
But it produces the problem that amplitude.getinstance is not a function. Could anyone give me some guidance?