Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery( document ).ready( function ( $ ) {
- var dm_insight_id = dmData.dm_insight_id;
- var email = dmData.email;
- var cart_items = dmData.line_items;
- var item_count = dmData.item_count;
- var ajax_url = dmData.ajax_url;
- var cartInsight = dmData.cartInsight;
- if(dm_insight_id != ''){
- (function(w,d,u,t,o,c){w['dmtrackingobjectname']=o;c=d.createElement(t);c.async=1;c.src=u;t=d.getElementsByTagName
- (t)[0];t.parentNode.insertBefore(c,t);w[o]=w[o]||function(){(w[o].q=w[o].q||[]).push(arguments);};
- })(window, document, '//static.trackedweb.net/js/_dmptv4.js', 'script', 'dmPt');
- }
- /*
- ** Every page load (inc add-to-cart from single product page)
- */
- console.log('–––––––––––––––––––––––––––');
- console.log('page loaded');
- console.log('email: ' + email);
- console.log(JSON.stringify(cartInsight));
- window.dmPt('track');
- if (typeof email != "undefined") { window.dmPt('identify', email); }
- window.dmPt("cartInsight", JSON.stringify(cartInsight) );
- /*
- ** AJAX add-to-cart from archive page
- */
- $( document.body ).on( 'added_to_cart removed_from_cart', function(event, fragments, cart_hash){
- console.log('–––––––––––––––––––––––––––');
- console.log('product added or removed to cart');
- console.log('email: ' + email);
- console.log(fragments.dm_cart_insight);
- window.dmPt('track');
- if (typeof email != "undefined") { window.dmPt('identify', email); }
- window.dmPt("cartInsight", JSON.stringify(fragments.dm_cart_insight) );
- });
- /*
- ** AJAX update cart (cart page)
- */
- $( document.body ).on( 'updated_cart_totals', dm_get_insight_data );
- function dm_get_insight_data() {
- $.ajax({
- url: ajax_url,
- type : 'POST',
- data : {
- action : 'dm_get_insight_data',
- /*post_id : post_id // Any other data to pass to function*/
- },
- success : function( response ) {
- console.log('–––––––––––––––––––––––––––');
- console.log('cart total updated');
- console.log(response);
- window.dmPt('track');
- if (typeof email != "undefined") { window.dmPt('identify', email); }
- window.dmPt("cartInsight", response );
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement