Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.32 KB | None | 0 0
  1. jQuery( document ).ready( function ( $ ) {
  2.    
  3.     var dm_insight_id = dmData.dm_insight_id;
  4.     var email = dmData.email;
  5.     var cart_items = dmData.line_items;
  6.     var item_count = dmData.item_count;
  7.     var ajax_url = dmData.ajax_url;
  8.     var cartInsight = dmData.cartInsight;
  9.  
  10.  
  11.     if(dm_insight_id != ''){
  12.  
  13.         (function(w,d,u,t,o,c){w['dmtrackingobjectname']=o;c=d.createElement(t);c.async=1;c.src=u;t=d.getElementsByTagName
  14.         (t)[0];t.parentNode.insertBefore(c,t);w[o]=w[o]||function(){(w[o].q=w[o].q||[]).push(arguments);};
  15.         })(window, document, '//static.trackedweb.net/js/_dmptv4.js', 'script', 'dmPt');
  16.     }
  17.  
  18.  
  19.    
  20.  
  21.     /*
  22.     ** Every page load (inc add-to-cart from single product page)
  23.     */
  24.     console.log('–––––––––––––––––––––––––––');
  25.     console.log('page loaded');
  26.     console.log('email: ' + email);
  27.     console.log(JSON.stringify(cartInsight));
  28.  
  29.     window.dmPt('track');
  30.     if (typeof email != "undefined") { window.dmPt('identify', email); }
  31.     window.dmPt("cartInsight", JSON.stringify(cartInsight) );
  32.        
  33.  
  34.     /*
  35.     ** AJAX add-to-cart from archive page
  36.     */
  37.     $( document.body ).on( 'added_to_cart removed_from_cart', function(event, fragments, cart_hash){
  38.  
  39.         console.log('–––––––––––––––––––––––––––');
  40.         console.log('product added or removed to cart');
  41.         console.log('email: ' + email);
  42.         console.log(fragments.dm_cart_insight);
  43.  
  44.         window.dmPt('track');
  45.         if (typeof email != "undefined") { window.dmPt('identify', email); }
  46.         window.dmPt("cartInsight", JSON.stringify(fragments.dm_cart_insight) );
  47.  
  48.     });
  49.  
  50.  
  51.  
  52.     /*
  53.     ** AJAX update cart (cart page)
  54.     */
  55.     $( document.body ).on( 'updated_cart_totals', dm_get_insight_data );
  56.     function dm_get_insight_data() {
  57.  
  58.         $.ajax({
  59.             url: ajax_url,
  60.             type : 'POST',
  61.             data : {
  62.                 action : 'dm_get_insight_data',
  63.                 /*post_id : post_id // Any other data to pass to function*/
  64.             },
  65.             success : function( response ) {
  66.  
  67.                 console.log('–––––––––––––––––––––––––––');
  68.                 console.log('cart total updated');
  69.                 console.log(response);
  70.                 window.dmPt('track');
  71.                 if (typeof email != "undefined") { window.dmPt('identify', email); }
  72.                 window.dmPt("cartInsight", response );
  73.                
  74.             }
  75.         });
  76.     }
  77.  
  78.  
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement