Changeset 2623775
- Timestamp:
- 11/03/2021 07:50:28 AM (4 years ago)
- Location:
- customerlabs-actionrecorder
- Files:
-
- 7 edited
- 9 copied
-
tags/1.3.0 (copied) (copied from customerlabs-actionrecorder/trunk)
-
tags/1.3.0/ActionRecorder.php (copied) (copied from customerlabs-actionrecorder/trunk/ActionRecorder.php) (4 diffs)
-
tags/1.3.0/Readme.md (copied) (copied from customerlabs-actionrecorder/trunk/Readme.md) (2 diffs)
-
tags/1.3.0/Readme.txt (copied) (copied from customerlabs-actionrecorder/trunk/Readme.txt) (2 diffs)
-
tags/1.3.0/class.cltracker-cookie.php (modified) (1 diff)
-
tags/1.3.0/class.cltracker-settings.php (copied) (copied from customerlabs-actionrecorder/trunk/class.cltracker-settings.php)
-
tags/1.3.0/integrations/ecommerce.php (copied) (copied from customerlabs-actionrecorder/trunk/integrations/ecommerce.php)
-
tags/1.3.0/integrations/ecommerce/woocommerce.php (copied) (copied from customerlabs-actionrecorder/trunk/integrations/ecommerce/woocommerce.php) (16 diffs)
-
tags/1.3.0/templates/identify.php (copied) (copied from customerlabs-actionrecorder/trunk/templates/identify.php)
-
tags/1.3.0/templates/track.php (copied) (copied from customerlabs-actionrecorder/trunk/templates/track.php) (1 diff)
-
trunk/ActionRecorder.php (modified) (4 diffs)
-
trunk/Readme.md (modified) (2 diffs)
-
trunk/Readme.txt (modified) (2 diffs)
-
trunk/class.cltracker-cookie.php (modified) (1 diff)
-
trunk/integrations/ecommerce/woocommerce.php (modified) (16 diffs)
-
trunk/templates/track.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
customerlabs-actionrecorder/tags/1.3.0/ActionRecorder.php
r2582041 r2623775 3 3 Plugin Name: Customerlabs ActionRecorder 4 4 Description: A simple implementation of e-commerce events tracking for ActionRecorder 5 Version: 1. 2.15 Version: 1.3.0 6 6 License: GPLv2 7 7 Author: CustomerLabs Digital Solutions Pvt. Ltd. … … 73 73 * 74 74 * 75 * @param string $event The name of the event to send to CustomerLabs. 76 * @param array $attributes An array of attributes to send to CustomerLabs. 77 * @param string $cached_event event triggered via ajax call need to be cleared 78 * 79 */ 80 public static function track( $event, $attributes = array(), $cached_event ) { 75 * @param array $tracks An array of events to send to CustomerLabs. 76 * 77 */ 78 public static function track( $tracks ) { 81 79 82 80 include_once( dirname( __FILE__ ) . '/templates/track.php' ); … … 429 427 430 428 // Track a custom page view event if the current page merits it. 431 $track = $this->get_current_page_track();429 $tracks = $this->get_current_page_track(); 432 430 $page = $this->get_current_page(); 433 431 434 if ( $track ) { 435 $cached_event = isset( $track['cached_event'] ) ? $track['cached_event'] : false; 436 self::$instance->cltracker->track( $track['event'], $track['attributes'], $cached_event ); 432 if ( $tracks ) { 433 self::$instance->cltracker->track( $tracks ); 437 434 } 438 435 … … 641 638 } 642 639 643 return apply_filters( 'cltracker_get_current_page_track', $track, $settings, $this );640 return apply_filters( 'cltracker_get_current_page_track', [ $track ], $settings, $this ); 644 641 } 645 642 /** -
customerlabs-actionrecorder/tags/1.3.0/Readme.md
r2582081 r2623775 54 54 ## Changelog 55 55 56 = 1.3.0 = 57 * Fixed multiple ajax events 58 * Fixed multiple events tracking on page load 59 56 60 = 1.2.1 = 57 61 * Bug Fix settings update issue … … 68 72 ## Upgrade Notice 69 73 74 = 1.3.0 = 75 Fixed multiple ajax events 76 Fixed multiple events tracking on page load 77 70 78 = 1.2.1 = 71 79 Bug Fix settings update issue -
customerlabs-actionrecorder/tags/1.3.0/Readme.txt
r2582082 r2623775 54 54 == Changelog == 55 55 56 = 1.3.0 = 57 * Fixed multiple ajax events 58 * Fixed multiple events tracking on page load 59 56 60 = 1.2.1 = 57 61 * Bug Fix settings update issue … … 68 72 == Upgrade Notice == 69 73 74 = 1.3.0 = 75 Fixed multiple ajax events 76 Fixed multiple events tracking on page load 77 70 78 = 1.2.1 = 71 79 Bug Fix settings update issue -
customerlabs-actionrecorder/tags/1.3.0/class.cltracker-cookie.php
r2060768 r2623775 45 45 46 46 /** 47 * Gets cookie value from the client side where name start with 48 * 49 * @param string $key Name of the cookie start with 50 * 51 * @since 1.0.0 52 * 53 */ 54 public static function get_cookies_start_with( $key ) { 55 56 $set = false; 57 $cookies = array(); 58 $cookie_name = "cltracker_" . $key . '_'; 59 foreach ($_COOKIE as $name => $value) { 60 if (stripos($name, $cookie_name) === 0) { 61 $cookies[] = $_COOKIE[$name]; 62 $set = true; 63 } 64 } 65 66 print_r($set); 67 68 if (!$set) { 69 return false; 70 } 71 72 return $cookies; 73 } 74 75 /** 47 76 * Deletes cookie from the client 48 77 * -
customerlabs-actionrecorder/tags/1.3.0/integrations/ecommerce/woocommerce.php
r2577817 r2623775 42 42 43 43 $args = func_get_args(); 44 $track = $args[0];44 $tracks = $args[0]; 45 45 $settings = $args[1]; 46 46 … … 57 57 ) 58 58 ); 59 } 60 61 } 62 63 return $track; 59 array_push($tracks, $track); 60 } 61 62 } 63 64 return $tracks; 64 65 } 65 66 … … 76 77 77 78 $args = func_get_args(); 78 $track = $args[0];79 $tracks = $args[0]; 79 80 $settings = $args[1]; 80 81 … … 105 106 ) 106 107 ); 107 } 108 } 109 110 return $track; 108 array_push($tracks, $track); 109 } 110 } 111 112 return $tracks; 111 113 } 112 114 … … 144 146 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 145 147 146 CLTracker_Cookie::set_cookie( 'added_to_cart' , json_encode(148 CLTracker_Cookie::set_cookie( 'added_to_cart' . '_' . $id, json_encode( 147 149 array( 148 150 'product_id' => $id, … … 172 174 $args = func_get_args(); 173 175 174 $track = $args[0];176 $tracks = $args[0]; 175 177 $settings = $args[1]; 176 178 177 179 if ( $settings['track_add_to_cart'] ) { 178 180 179 if ( false !== ( $cookie = CLTracker_Cookie::get_cookie( 'added_to_cart' ) ) ) {181 if ( false !== ( $cookies = CLTracker_Cookie::get_cookies_start_with( 'added_to_cart' ) ) ) { 180 182 181 183 if ( ! is_object( WC()->cart ) ) { 182 return $track ;184 return $tracks; 183 185 } 184 186 185 $_product = json_decode(stripslashes($cookie)); 186 187 if ( is_object( $_product ) ) { 188 $product = wc_get_product( $_product->product_id ); 189 190 if ( $product ) { 191 $image_id = $product->get_image_id(); 192 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 193 $item = array( 194 'product_id' => $product->get_id(), 195 'product_name' => $product->get_title(), 196 'product_price' => $product->get_price(), 197 'product_quantity' => $_product->product_quantity, 198 'product_sku' => $product->get_sku(), 199 'product_image' => $image_url, 200 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 201 ); 202 203 $track = array( 204 'event' => __( 'Added to cart', 'cltracker' ), 205 'attributes' => array( 206 "customProperties" => array( 207 "currency" => get_woocommerce_currency(), 208 "content_type" => "product_group" 187 188 if ( is_array( $cookies ) ) { 189 190 foreach ( $cookies as $cookie ) { 191 192 $_product = json_decode(stripslashes($cookie)); 193 $product = wc_get_product( $_product->product_id ); 194 195 if ( $product ) { 196 $image_id = $product->get_image_id(); 197 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 198 $item = array( 199 'product_id' => $product->get_id(), 200 'product_name' => $product->get_title(), 201 'product_price' => $product->get_price(), 202 'product_quantity' => $_product->product_quantity, 203 'product_sku' => $product->get_sku(), 204 'product_image' => $image_url, 205 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 206 ); 207 208 $track = array( 209 'event' => __( 'Added to cart', 'cltracker' ), 210 'attributes' => array( 211 "customProperties" => array( 212 "currency" => get_woocommerce_currency(), 213 "content_type" => "product_group" 214 ), 215 "productProperties" => array( 216 $item 217 ) 209 218 ), 210 "productProperties" => array( 211 $item 212 ) 213 ), 214 'cached_event' => 'added_to_cart' 215 ); 219 'cached_event' => 'added_to_cart_' . $_product->product_id 220 ); 221 array_push($tracks, $track); 222 } 216 223 } 217 224 } … … 220 227 } 221 228 222 return $track ;229 return $tracks; 223 230 } 224 231 … … 250 257 $product = wc_get_product($cart_item['product_id']); 251 258 252 CLTracker_Cookie::set_cookie( 'removed_from_cart' , json_encode(259 CLTracker_Cookie::set_cookie( 'removed_from_cart' . '_' . $cart_item['product_id'], json_encode( 253 260 array( 254 261 'product_id' => $cart_item['product_id'], … … 275 282 $args = func_get_args(); 276 283 277 $track = $args[0];284 $tracks = $args[0]; 278 285 $settings = $args[1]; 279 286 280 287 if ( $settings['track_remove_from_cart'] ) { 281 if ( false !== ( $cookie = CLTracker_Cookie::get_cookie( 'removed_from_cart' ) ) ) {288 if ( false !== ( $cookies = CLTracker_Cookie::get_cookies_start_with( 'removed_from_cart' ) ) ) { 282 289 283 290 if ( ! is_object( WC()->cart ) ) { 284 return $track ;291 return $tracks; 285 292 } 286 293 287 $_product = json_decode( stripslashes($cookie) ); 288 289 if ( is_object( $_product ) ) { 290 $product = wc_get_product( $_product->product_id ); 291 292 if ( $product ) { 293 $item = array( 294 'product_id' => $product->get_id(), 295 'product_sku' => $product->get_sku(), 296 'product_name' => $product->get_title(), 297 'product_price' => $product->get_price(), 298 'product_quantity' => 0, 299 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 300 ); 301 302 $track = array( 303 'event' => __( 'Removed from cart', 'cltracker' ), 304 'attributes' => array( 305 "productProperties" => array( 306 $item 307 ) 308 ), 309 'cached_event' => 'removed_from_cart' 310 ); 294 295 if ( is_array( $cookies ) ) { 296 297 foreach ( $cookies as $cookie ){ 298 $_product = json_decode( stripslashes($cookie) ); 299 $product = wc_get_product( $_product->product_id ); 300 301 if ( $product ) { 302 $item = array( 303 'product_id' => $product->get_id(), 304 'product_sku' => $product->get_sku(), 305 'product_name' => $product->get_title(), 306 'product_price' => $product->get_price(), 307 'product_quantity' => 0, 308 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 309 ); 310 311 $track = array( 312 'event' => __( 'Removed from cart', 'cltracker' ), 313 'attributes' => array( 314 "productProperties" => array( 315 $item 316 ) 317 ), 318 'cached_event' => 'removed_from_cart_' . $_product->product_id 319 ); 320 array_push($tracks, $track); 321 } 311 322 } 312 323 } … … 314 325 } 315 326 316 return $track ;327 return $tracks; 317 328 } 318 329 … … 327 338 public function completed_order() { 328 339 $args = func_get_args(); 329 $track = $args[0];340 $tracks = $args[0]; 330 341 $settings = $args[1]; 331 342 … … 376 387 ) 377 388 ); 378 389 array_push($tracks, $track); 379 390 } 380 391 } 381 392 } 382 393 383 return $track ;394 return $tracks; 384 395 } 385 396 … … 481 492 482 493 $args = func_get_args(); 483 $track = $args[0];494 $tracks = $args[0]; 484 495 $settings = $args[1]; 485 496 … … 487 498 488 499 if ( ! is_object( WC()->cart ) ) { 489 return $track ;500 return $tracks; 490 501 } 491 502 492 503 if ( !is_checkout() ) { 493 return $track ;504 return $tracks; 494 505 } 495 506 … … 499 510 500 511 if ( count($items) == 0 ){ 501 return $track ;512 return $tracks; 502 513 } 503 514 … … 534 545 ) 535 546 ); 536 537 } 538 539 return $track ;547 array_push($tracks, $track); 548 } 549 550 return $tracks; 540 551 } 541 552 -
customerlabs-actionrecorder/tags/1.3.0/templates/track.php
r2577640 r2623775 1 1 <script type="text/javascript" id="cl_track"> 2 2 window.clWordpressTrack = function(){ 3 _cl.track(<?php echo '"' . esc_js( $event ) . '"' ?><?php if ( ! empty( $attributes ) ) { echo ', ' . json_encode( CLTracker_WordPress::esc_js_deep( $attributes ) ); } else { echo ', {}'; } ?>); 3 <?php 4 foreach ($tracks as $track) { 5 if ( $track ) { 6 $cached_event = isset( $track['cached_event'] ) ? $track['cached_event'] : false; 7 $event = $track['event']; 8 $attributes = $track['attributes']; 9 if ( $cached_event ) : 10 ?> 11 12 _cl.ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>"; 13 14 jQuery( document ).ready( function( $ ) { 15 var data = { 16 action : 'cltracker_unset_cookie', 17 key : '<?php echo esc_js( $cached_event ); ?>', 18 19 }, 20 success = function( response ) { 21 console.log( response ); 22 }; 23 24 $.post( _cl.ajaxurl, data, success ); 25 }); 26 27 <?php 28 endif; 29 ?> 30 _cl.track(<?php echo '"' . esc_js( $event ) . '"' ?><?php if ( ! empty( $attributes ) ) { echo ', ' . json_encode( CLTracker_WordPress::esc_js_deep( $attributes ) ); } else { echo ', {}'; } ?>); 31 <?php 32 } 33 }?> 4 34 }; 5 35 6 7 <?php8 if ( $cached_event ) :9 ?>10 11 _cl.ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>";12 13 jQuery( document ).ready( function( $ ) {14 var data = {15 action : 'cltracker_unset_cookie',16 key : '<?php echo esc_js( $cached_event ); ?>',17 18 },19 success = function( response ) {20 console.log( response );21 };22 23 $.post( _cl.ajaxurl, data, success );24 });25 26 <?php27 endif;28 ?>29 30 36 </script> -
customerlabs-actionrecorder/trunk/ActionRecorder.php
r2582041 r2623775 3 3 Plugin Name: Customerlabs ActionRecorder 4 4 Description: A simple implementation of e-commerce events tracking for ActionRecorder 5 Version: 1. 2.15 Version: 1.3.0 6 6 License: GPLv2 7 7 Author: CustomerLabs Digital Solutions Pvt. Ltd. … … 73 73 * 74 74 * 75 * @param string $event The name of the event to send to CustomerLabs. 76 * @param array $attributes An array of attributes to send to CustomerLabs. 77 * @param string $cached_event event triggered via ajax call need to be cleared 78 * 79 */ 80 public static function track( $event, $attributes = array(), $cached_event ) { 75 * @param array $tracks An array of events to send to CustomerLabs. 76 * 77 */ 78 public static function track( $tracks ) { 81 79 82 80 include_once( dirname( __FILE__ ) . '/templates/track.php' ); … … 429 427 430 428 // Track a custom page view event if the current page merits it. 431 $track = $this->get_current_page_track();429 $tracks = $this->get_current_page_track(); 432 430 $page = $this->get_current_page(); 433 431 434 if ( $track ) { 435 $cached_event = isset( $track['cached_event'] ) ? $track['cached_event'] : false; 436 self::$instance->cltracker->track( $track['event'], $track['attributes'], $cached_event ); 432 if ( $tracks ) { 433 self::$instance->cltracker->track( $tracks ); 437 434 } 438 435 … … 641 638 } 642 639 643 return apply_filters( 'cltracker_get_current_page_track', $track, $settings, $this );640 return apply_filters( 'cltracker_get_current_page_track', [ $track ], $settings, $this ); 644 641 } 645 642 /** -
customerlabs-actionrecorder/trunk/Readme.md
r2582081 r2623775 54 54 ## Changelog 55 55 56 = 1.3.0 = 57 * Fixed multiple ajax events 58 * Fixed multiple events tracking on page load 59 56 60 = 1.2.1 = 57 61 * Bug Fix settings update issue … … 68 72 ## Upgrade Notice 69 73 74 = 1.3.0 = 75 Fixed multiple ajax events 76 Fixed multiple events tracking on page load 77 70 78 = 1.2.1 = 71 79 Bug Fix settings update issue -
customerlabs-actionrecorder/trunk/Readme.txt
r2582082 r2623775 54 54 == Changelog == 55 55 56 = 1.3.0 = 57 * Fixed multiple ajax events 58 * Fixed multiple events tracking on page load 59 56 60 = 1.2.1 = 57 61 * Bug Fix settings update issue … … 68 72 == Upgrade Notice == 69 73 74 = 1.3.0 = 75 Fixed multiple ajax events 76 Fixed multiple events tracking on page load 77 70 78 = 1.2.1 = 71 79 Bug Fix settings update issue -
customerlabs-actionrecorder/trunk/class.cltracker-cookie.php
r2060768 r2623775 45 45 46 46 /** 47 * Gets cookie value from the client side where name start with 48 * 49 * @param string $key Name of the cookie start with 50 * 51 * @since 1.0.0 52 * 53 */ 54 public static function get_cookies_start_with( $key ) { 55 56 $set = false; 57 $cookies = array(); 58 $cookie_name = "cltracker_" . $key . '_'; 59 foreach ($_COOKIE as $name => $value) { 60 if (stripos($name, $cookie_name) === 0) { 61 $cookies[] = $_COOKIE[$name]; 62 $set = true; 63 } 64 } 65 66 print_r($set); 67 68 if (!$set) { 69 return false; 70 } 71 72 return $cookies; 73 } 74 75 /** 47 76 * Deletes cookie from the client 48 77 * -
customerlabs-actionrecorder/trunk/integrations/ecommerce/woocommerce.php
r2577817 r2623775 42 42 43 43 $args = func_get_args(); 44 $track = $args[0];44 $tracks = $args[0]; 45 45 $settings = $args[1]; 46 46 … … 57 57 ) 58 58 ); 59 } 60 61 } 62 63 return $track; 59 array_push($tracks, $track); 60 } 61 62 } 63 64 return $tracks; 64 65 } 65 66 … … 76 77 77 78 $args = func_get_args(); 78 $track = $args[0];79 $tracks = $args[0]; 79 80 $settings = $args[1]; 80 81 … … 105 106 ) 106 107 ); 107 } 108 } 109 110 return $track; 108 array_push($tracks, $track); 109 } 110 } 111 112 return $tracks; 111 113 } 112 114 … … 144 146 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 145 147 146 CLTracker_Cookie::set_cookie( 'added_to_cart' , json_encode(148 CLTracker_Cookie::set_cookie( 'added_to_cart' . '_' . $id, json_encode( 147 149 array( 148 150 'product_id' => $id, … … 172 174 $args = func_get_args(); 173 175 174 $track = $args[0];176 $tracks = $args[0]; 175 177 $settings = $args[1]; 176 178 177 179 if ( $settings['track_add_to_cart'] ) { 178 180 179 if ( false !== ( $cookie = CLTracker_Cookie::get_cookie( 'added_to_cart' ) ) ) {181 if ( false !== ( $cookies = CLTracker_Cookie::get_cookies_start_with( 'added_to_cart' ) ) ) { 180 182 181 183 if ( ! is_object( WC()->cart ) ) { 182 return $track ;184 return $tracks; 183 185 } 184 186 185 $_product = json_decode(stripslashes($cookie)); 186 187 if ( is_object( $_product ) ) { 188 $product = wc_get_product( $_product->product_id ); 189 190 if ( $product ) { 191 $image_id = $product->get_image_id(); 192 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 193 $item = array( 194 'product_id' => $product->get_id(), 195 'product_name' => $product->get_title(), 196 'product_price' => $product->get_price(), 197 'product_quantity' => $_product->product_quantity, 198 'product_sku' => $product->get_sku(), 199 'product_image' => $image_url, 200 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 201 ); 202 203 $track = array( 204 'event' => __( 'Added to cart', 'cltracker' ), 205 'attributes' => array( 206 "customProperties" => array( 207 "currency" => get_woocommerce_currency(), 208 "content_type" => "product_group" 187 188 if ( is_array( $cookies ) ) { 189 190 foreach ( $cookies as $cookie ) { 191 192 $_product = json_decode(stripslashes($cookie)); 193 $product = wc_get_product( $_product->product_id ); 194 195 if ( $product ) { 196 $image_id = $product->get_image_id(); 197 $image_url = wp_get_attachment_image_url( $image_id, 'full' ); 198 $item = array( 199 'product_id' => $product->get_id(), 200 'product_name' => $product->get_title(), 201 'product_price' => $product->get_price(), 202 'product_quantity' => $_product->product_quantity, 203 'product_sku' => $product->get_sku(), 204 'product_image' => $image_url, 205 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 206 ); 207 208 $track = array( 209 'event' => __( 'Added to cart', 'cltracker' ), 210 'attributes' => array( 211 "customProperties" => array( 212 "currency" => get_woocommerce_currency(), 213 "content_type" => "product_group" 214 ), 215 "productProperties" => array( 216 $item 217 ) 209 218 ), 210 "productProperties" => array( 211 $item 212 ) 213 ), 214 'cached_event' => 'added_to_cart' 215 ); 219 'cached_event' => 'added_to_cart_' . $_product->product_id 220 ); 221 array_push($tracks, $track); 222 } 216 223 } 217 224 } … … 220 227 } 221 228 222 return $track ;229 return $tracks; 223 230 } 224 231 … … 250 257 $product = wc_get_product($cart_item['product_id']); 251 258 252 CLTracker_Cookie::set_cookie( 'removed_from_cart' , json_encode(259 CLTracker_Cookie::set_cookie( 'removed_from_cart' . '_' . $cart_item['product_id'], json_encode( 253 260 array( 254 261 'product_id' => $cart_item['product_id'], … … 275 282 $args = func_get_args(); 276 283 277 $track = $args[0];284 $tracks = $args[0]; 278 285 $settings = $args[1]; 279 286 280 287 if ( $settings['track_remove_from_cart'] ) { 281 if ( false !== ( $cookie = CLTracker_Cookie::get_cookie( 'removed_from_cart' ) ) ) {288 if ( false !== ( $cookies = CLTracker_Cookie::get_cookies_start_with( 'removed_from_cart' ) ) ) { 282 289 283 290 if ( ! is_object( WC()->cart ) ) { 284 return $track ;291 return $tracks; 285 292 } 286 293 287 $_product = json_decode( stripslashes($cookie) ); 288 289 if ( is_object( $_product ) ) { 290 $product = wc_get_product( $_product->product_id ); 291 292 if ( $product ) { 293 $item = array( 294 'product_id' => $product->get_id(), 295 'product_sku' => $product->get_sku(), 296 'product_name' => $product->get_title(), 297 'product_price' => $product->get_price(), 298 'product_quantity' => 0, 299 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 300 ); 301 302 $track = array( 303 'event' => __( 'Removed from cart', 'cltracker' ), 304 'attributes' => array( 305 "productProperties" => array( 306 $item 307 ) 308 ), 309 'cached_event' => 'removed_from_cart' 310 ); 294 295 if ( is_array( $cookies ) ) { 296 297 foreach ( $cookies as $cookie ){ 298 $_product = json_decode( stripslashes($cookie) ); 299 $product = wc_get_product( $_product->product_id ); 300 301 if ( $product ) { 302 $item = array( 303 'product_id' => $product->get_id(), 304 'product_sku' => $product->get_sku(), 305 'product_name' => $product->get_title(), 306 'product_price' => $product->get_price(), 307 'product_quantity' => 0, 308 'product_category' => implode( ', ', wp_list_pluck( wc_get_product_terms( $product->get_id(), 'product_cat' ), 'name' ) ), 309 ); 310 311 $track = array( 312 'event' => __( 'Removed from cart', 'cltracker' ), 313 'attributes' => array( 314 "productProperties" => array( 315 $item 316 ) 317 ), 318 'cached_event' => 'removed_from_cart_' . $_product->product_id 319 ); 320 array_push($tracks, $track); 321 } 311 322 } 312 323 } … … 314 325 } 315 326 316 return $track ;327 return $tracks; 317 328 } 318 329 … … 327 338 public function completed_order() { 328 339 $args = func_get_args(); 329 $track = $args[0];340 $tracks = $args[0]; 330 341 $settings = $args[1]; 331 342 … … 376 387 ) 377 388 ); 378 389 array_push($tracks, $track); 379 390 } 380 391 } 381 392 } 382 393 383 return $track ;394 return $tracks; 384 395 } 385 396 … … 481 492 482 493 $args = func_get_args(); 483 $track = $args[0];494 $tracks = $args[0]; 484 495 $settings = $args[1]; 485 496 … … 487 498 488 499 if ( ! is_object( WC()->cart ) ) { 489 return $track ;500 return $tracks; 490 501 } 491 502 492 503 if ( !is_checkout() ) { 493 return $track ;504 return $tracks; 494 505 } 495 506 … … 499 510 500 511 if ( count($items) == 0 ){ 501 return $track ;512 return $tracks; 502 513 } 503 514 … … 534 545 ) 535 546 ); 536 537 } 538 539 return $track ;547 array_push($tracks, $track); 548 } 549 550 return $tracks; 540 551 } 541 552 -
customerlabs-actionrecorder/trunk/templates/track.php
r2577640 r2623775 1 1 <script type="text/javascript" id="cl_track"> 2 2 window.clWordpressTrack = function(){ 3 _cl.track(<?php echo '"' . esc_js( $event ) . '"' ?><?php if ( ! empty( $attributes ) ) { echo ', ' . json_encode( CLTracker_WordPress::esc_js_deep( $attributes ) ); } else { echo ', {}'; } ?>); 3 <?php 4 foreach ($tracks as $track) { 5 if ( $track ) { 6 $cached_event = isset( $track['cached_event'] ) ? $track['cached_event'] : false; 7 $event = $track['event']; 8 $attributes = $track['attributes']; 9 if ( $cached_event ) : 10 ?> 11 12 _cl.ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>"; 13 14 jQuery( document ).ready( function( $ ) { 15 var data = { 16 action : 'cltracker_unset_cookie', 17 key : '<?php echo esc_js( $cached_event ); ?>', 18 19 }, 20 success = function( response ) { 21 console.log( response ); 22 }; 23 24 $.post( _cl.ajaxurl, data, success ); 25 }); 26 27 <?php 28 endif; 29 ?> 30 _cl.track(<?php echo '"' . esc_js( $event ) . '"' ?><?php if ( ! empty( $attributes ) ) { echo ', ' . json_encode( CLTracker_WordPress::esc_js_deep( $attributes ) ); } else { echo ', {}'; } ?>); 31 <?php 32 } 33 }?> 4 34 }; 5 35 6 7 <?php8 if ( $cached_event ) :9 ?>10 11 _cl.ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>";12 13 jQuery( document ).ready( function( $ ) {14 var data = {15 action : 'cltracker_unset_cookie',16 key : '<?php echo esc_js( $cached_event ); ?>',17 18 },19 success = function( response ) {20 console.log( response );21 };22 23 $.post( _cl.ajaxurl, data, success );24 });25 26 <?php27 endif;28 ?>29 30 36 </script>
Note: See TracChangeset
for help on using the changeset viewer.