Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var sourceURL = window.location.origin + '/cart/add.js';
- var productId = '12321242611754';
- var eventType = 'Adoric - Carousel Recipe Rose Paloma A/B';
- var data = JSON.stringify({id: productId, quantity: 1});
- var eventElementType = 'Added to the cart';
- var productName = 'Rose Paloma One Item (Soda Press Pink Grapefruit - 500ml)';
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- xhr.open('POST', sourceURL);
- xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
- xhr.setRequestHeader('cache-control', 'no-cache');
- function pushCustomGAEvent(eventType, eventElementType, elementId) {
- if (window.preDataLayer) {
- window.preDataLayer.push({
- event: 'newEvent',
- newEventData: {
- type: eventType,
- elementType: eventElementType,
- elementId: elementId
- }
- });
- }
- }
- xhr.addEventListener('readystatechange', function() {
- if (this.readyState === 4) {
- pushCustomGAEvent(eventType, eventElementType, productName);
- window.location.href = window.location.origin + '/cart';
- }
- });
- xhr.send([data]);
- })();
Add Comment
Please, Sign In to add comment