1 /* 2 * Dotdigital - Abandoned Cart Script 3 * 4 * 5 * The main functionality of this script is to: 6 * - Create an instance of the abandoned cart tracking session, using the function provided by Dotdigital. 7 * - On page load, we send user identification information to Dotdigital, if available - using the function provided by Dotdigital. 8 * - On page load, we also send cart information information to Dotdigital, if available - using the function provided by Dotdigital. 9 * - When certain in-page events (add to cart, remove from cart) occur, we send the updated cart info to DotDigital - using the function provided by Dotdigital. 10 * 11 * Note: 12 * By default the window will have an esoTracking property. 13 * This property is an object containing page, catalogue, product, cart etc info in a generic format. 14 * We use the esoTracking object as the source of cart and config information. 15 * 16 */ 17 18 19 // Do not change this 20 (function(w,d,u,t,o,c){w['dmtrackingobjectname']=o;c=d.createElement(t);c.async=1;c.src=u;t=d.getElementsByTagName 21 (t)[0];t.parentNode.insertBefore(c,t);w[o]=w[o]||function(){(w[o].q=w[o].q||[]).push(arguments);}; 22 })(window, document, '//static.trackedweb.net/js/_dmptv4.js', 'script', 'dmPt'); 23 window.dmPt('create', esoTracking.cartConfig.DotDigital.account_id, esoTracking.cartConfig.DotDigital.domain); 24 window.dmPt('track'); 25 /* ---------------------------------------------------------------------------------------------------- 26 Identify the contact: 27 The code below needs to be executed on every single page, after the cart has been created. 28 Failure to do so may result in contacts getting an abandoned cart email too early. 29 ---------------------------------------------------------------------------------------------------- */ 30 if( esoTracking != undefined ){ 31 if( esoTracking.cartConfig != undefined ){ 32 if( esoTracking.cartConfig.DotDigital != undefined ){ 33 if( (esoTracking.cartConfig.DotDigital.user_email_address)){ 34 // only call the identify function if we have an email address 35 window.dmPt("identify", esoTracking.cartConfig.DotDigital.user_email_address ); // Inject user email address. 36 } 37 } 38 } 39 } 40 41 /* ---------------------------------------------------------------------------------------------------- 42 Supplying your cart: 43 The code below needs to be executed on every single page, after the cart has been created. 44 Failure to do so may result in contacts getting an abandoned cart email too early. 45 ---------------------------------------------------------------------------------------------------- */ 46 47 // Send info on pageLoad 48 sendCartChangeInfoToDD(esoTracking.load); 49 50 // Wait until jQuery has been loaded 51 $(function(){ 52 // listen for any eso-tracking events 53 $(window).on('eso-tracking', function(evt, data){ 54 if(data.type == 'add-cart'){ 55 sendCartChangeInfoToDD(data) 56 } 57 else if(data.type == 'remove-cart'){ 58 sendCartChangeInfoToDD(data) 59 } 60 }); 61 }) 62 63 64 // This function gets called when the cart is updated, to send new cart status to DotDigital 65 function sendCartChangeInfoToDD(trackingObj) { 66 67 if( !esoTracking || !esoTracking.cartConfig || !esoTracking.cartConfig.DotDigital ) { 68 // Required info is missing! 69 return; 70 } 71 72 // Initial value from page load 73 var cart_to_use = esoTracking.load.cart; 74 75 // But if there has been adding or removing to the cart, use those values instead 76 if( esoTracking.ajax && (esoTracking.ajax.length > 0) ){ 77 // so we get the cart object from the last ajax call, 78 // if the ajax call was adding or removing an item. 79 esoTracking.ajax.forEach( function(x, i) { 80 if( x.action == 'item added' || x.action == 'item removed' ){ 81 cart_to_use = x.cart; 82 } 83 }); 84 // If we have updated the cart, we also want to use the new values for the cartID and retry link 85 if( window.orderInformation != undefined ){ 86 if( window.orderInformation.orderid ){ 87 esoTracking.cartConfig.DotDigital.cartID = window.orderInformation.orderid; 88 }; 89 90 if( window.orderInformation.retryLink ){ 91 esoTracking.cartConfig.DotDigital.cartUrl = window.orderInformation.retryLink + '&c=' + esoTracking.cartConfig.DotDigital.customer_id; 92 } 93 } 94 } 95 96 // Recalculate cart info 97 var base_url = esoTracking.cartConfig.DotDigital.baseUrl; 98 var cart_line_items = []; 99 try{
100 cart_to_use.products.forEach( function(x, i) { 101 var this_line_item = { 102 'sku': x.id, 103 'name': x.name, 104 'description': x.productDescription, 105 'category': x.category.replaceAll( '/', ' > ' ), 106 'other': '', 107 'unitPrice': Number(x.unitPrice), 108 'salePrice': Number(x.unitPrice) - Number(x.unitDiscount), 109 'quantity': x.quantity, 110 'totalPrice': Number(x.price), 111 'imageUrl': base_url + 'productimages/medium/' + x.image, 112 'productUrl': base_url + x.canonical 113 }; 114 cart_line_items.push( this_line_item ); 115 }); 116 } 117 catch( e ){ 118 } 119 120 // call the DotDigital tracking function, as specified for pageload 121 try{ 122 if( cart_to_use ){ 123 // so we have something in the cart - call the cart function 124 window.dmPt("cartInsight", { 125 // You must setup all of these variables 126 "programID": esoTracking.cartConfig.DotDigital.programID, // Get this from the Program Builder in dotmailer 127 "cartDelay": esoTracking.cartConfig.DotDigital.cartDelay, // This is the time, in minutes, we wait before sending out the email 128 "cartID": esoTracking.cartConfig.DotDigital.cartID, // The ID of your shopping cart, this should be unique 129 "cartPhase": esoTracking.cartConfig.DotDigital.cartPhase, // Set to CUSTOMER_LOGIN on all pages and ORDER_COMPLETE on final page 130 "currency": esoTracking.cartConfig.DotDigital.currency, // The currency that the prices are in (e.g. USD or GBP) 131 "subtotal": cart_to_use.subtotalItems, // The cart subtotal amount 132 "discountAmount": Number(cart_to_use.discountItems) + Number(cart_to_use.discountOrder), // The amount discounted on the entire order 133 "shipping": cart_to_use.freight, // The amount of shipping included on the entire order 134 "taxAmount": cart_to_use.tax, // The amount of tax included on the entire order 135 "grandTotal": cart_to_use.total, // The final total of the order, including tax, discounts, etc, if known 136 "cartUrl": esoTracking.cartConfig.DotDigital.cartUrl, // Your website must be able to provide a unique URL to a basket 137 138 /* ---------------------------------------------------------------------------------------------------- 139 Setup the cart items 140 For each product in the cart, create an item in the lineItems array. 141 ---------------------------------------------------------------------------------------------------- */ 142 "lineItems": cart_line_items 143 }); 144 } 145 } 146 catch( e ){ 147 } 148 return; 149 }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.