Last active
June 1, 2021 08:08
-
-
Save davidknipe/89a155be3d805c0c00b44b743a1463d1 to your computer and use it in GitHub Desktop.
Optimizely Data Platform tracking script for Foundation sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This pops up a modal form when a certain element is clicked (element with id of 'joinButton' in this case) | |
if (document.getElementById('joinButton')) { | |
var joinButton = document.getElementById('joinButton'); | |
joinButton.addEventListener("click", | |
function (event) { | |
zaius.dispatch( | |
'web', | |
'showContent', { | |
contentId: 'mosey_club_modal_form_message_a_web_modal', // this is the id of the modal from ODP > Campaigns > edit campaign > Content Id | |
target: { | |
selector: '', | |
position: 'modal' | |
} | |
}); | |
event.preventDefault(); | |
}); | |
} | |
// Product detail view | |
if (document.getElementById('productCode')) { | |
var productCode = document.getElementById('productCode'); | |
zaius.event('product', { action: 'detail', product_id: productCode.value }); | |
} | |
if (document.getElementById('jsCheckoutForm')) { | |
var productCode = document.getElementById('productCode'); | |
zaius.event('checkout', { action: 'start' }); | |
} | |
if (window.location.href.indexOf("order-confirmation") > 0) | |
{ | |
var productCode = document.getElementById('productCode'); | |
zaius.event('checkout', { action: 'complete' }); | |
} | |
$(document).ready(function () { | |
// Add to cart | |
$(document).find('.addToCart').each(function (i, e) { | |
$(e).click(function () { | |
let code = $(this).attr('data'); | |
zaius.event('product', { action: 'add_to_cart', product_id: code }); | |
}); | |
}); | |
// Add to wishlist | |
$(document).find('.addToWishlist').each(function (i, e) { | |
$(e).click(function () { | |
let code = $(this).attr('data'); | |
zaius.event('product', { action: 'add_to_wishlist', product_id: code }); | |
}); | |
}); | |
// Remove from cart | |
$('#js-cart-popover').on('click', '.jsRemoveCartItem', function () { | |
let code = $(this).attr('code'); | |
zaius.event('product', { action: 'remove_from_cart', product_id: code }); | |
}); | |
$('.large-cart').on('click', '.jsRemoveCartItem', function () { | |
let code = $(this).attr('code'); | |
zaius.event('product', { action: 'remove_from_cart', product_id: code }); | |
}); | |
// Remove from wishlist | |
$('#js-wishlist-popover').on('click', '.jsRemoveCartItem', function () { | |
let code = $(this).attr('code'); | |
zaius.event('product', { action: 'remove_from_wishlist', product_id: code }); | |
}); | |
$('.my-account').on('click', '.deleteLineItemWishlist', function () { | |
let code = $(this).attr('data'); | |
zaius.event('product', { action: 'remove_from_cart', product_id: code }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment