Advertisement
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)';
- fetch(sourceURL, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json;charset=utf-8',
- 'cache-control': 'no-cache'
- },
- body: data
- }).then(responce => {
- if (responce.status == 200){
- pushCustomGAEvent(eventType, eventElementType, productName);
- window.location.href = window.location.origin + '/cart';
- }
- }).catch(e => console.error(e))
- function pushCustomGAEvent(eventType, eventElementType, elementId) {
- if (window.preDataLayer) {
- window.preDataLayer.push({
- event: 'newEvent',
- newEventData: {
- type: eventType,
- elementType: eventElementType,
- elementId: elementId
- }
- });
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement