Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var sourceURL = 'https://sodastream.com/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');
- function pushCustomGAEvent(eventType, eventElementType, elementId) {
- if (window.preDataLayer) {
- window.preDataLayer.push({
- event: 'newEvent',
- newEventData: {
- type: eventType,
- elementType: eventElementType,
- elementId: elementId
- }
- });
- }
- }
- function pushEcommerceEvent(productListName, productId) {
- window.preDataLayer.push({
- "event": "newEvent",
- "newEventData": {
- "ecommerce": {
- "add": {
- "list": productListName,
- "products": [
- {
- "variant_id": productId,
- "quantity": 1
- }
- ]
- }
- },
- "type": "ecommerceData"
- }
- })
- }
- xhr.addEventListener('readystatechange', function() {
- if (this.readyState === 4) {
- pushCustomGAEvent(eventType, eventElementType, productName);
- pushEcommerceEvent(eventType, productId);
- }
- });
- xhr.send([data]);
- })();
Add Comment
Please, Sign In to add comment