Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- (function() {
- function adoricAddToCart(productId) {
- var data = {
- "id": productId,
- "quantity":1
- };
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- xhr.addEventListener('readystatechange', function () {
- if (this.readyState === 4) {
- console.log(this.responseText);
- window.location.reload();
- }
- });
- xhr.open('POST', window.location.origin + '/cart/add.js');
- xhr.setRequestHeader('content-type', 'application/json');
- xhr.setRequestHeader('cache-control', 'no-cache');
- xhr.send(JSON.stringify(data));
- }
- if (window.Element && !Element.prototype.closest) {
- Element.prototype.closest = function(s) {
- var matches = (this.document || this.ownerDocument).querySelectorAll(s),
- i,
- el = this;
- do {
- i = matches.length;
- while (--i >= 0 && matches.item(i) !== el) {};
- } while ((i < 0) && (el = el.parentElement));
- return el;
- };
- }
- var currentCampaignRepeater = document.querySelector('.' + self.identifier + ' .repeater-content');
- currentCampaignRepeater.addEventListener('click', function(event) {
- var productItem = event.target.closest('.repeater-item');
- if (event.target.getAttribute('role') === 'button' && productItem) {
- var productInformation = JSON.parse(productItem.dataset.productInfo);
- console.log('productInformation - ', productInformation);
- var productId = 'someID'; /* take it from productInformation obj*/
- window.ga && window.ga('t0.send', 'event', {
- eventCategory: "Adoric - " + self.campaignTitle + '(' + self.versionTitle + ')',
- eventAction: 'click',
- eventLabel: 'Added to the cart - ' + productInformation.title,
- });
- adoricAddToCart(productId);
- }
- });
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement