public static function add_tracker_code() { ?> <script type="text/javascript"> var _cio = _cio || []; (function() { var a,b,c;a=function(f){return function(){_cio.push([f]. concat(Array.prototype.slice.call(arguments,0)))}};b=["load","identify", "sidentify","track","page"];for(c=0;c<b.length;c++){_cio[b[c]]=a(b[c])}; var t = document.createElement('script'), s = document.getElementsByTagName('script')[0]; t.async = true; t.id = 'cio-tracker'; t.setAttribute('data-site-id', '<?php echo self::$site_id; ?> ' ); t.src = 'https://assets.customer.io/assets/track.js'; s.parentNode.insertBefore(t, s); })(); </script> <?php if (is_user_logged_in()) { // show for logged in users only. Other visitors can be identified via other methods. $uid = EDD_Segment_Identity::get_uid_from_user_id(get_current_user_id()); $user = get_user_by('id', get_current_user_id()); $first_name = $user->first_name; $email = $user->user_email; $created = strtotime($user->user_registered); ?> <script type="text/javascript"> _cio.identify({ id: '<?php echo $uid; ?> ', email: '<?php echo $email; ?> ', created_at: <?php echo $created; ?> , first_name: '<?php echo $first_name; ?> ' }); </script> <?php } elseif (EDD_Segment_Identity::has_uid()) { $uid = EDD_Segment_Identity::get_current_visitor_uid(); ?> <script type="text/javascript"> _cio.identify({ id: '<?php echo $uid; ?> ' }); </script> <?php } ?> <?php }
/** * Find old pending carts and consider them abandoned. * @return null */ public static function find_old_abandoned_carts() { $time = time(); $thirty_mins_ago = $time - apply_filters('find_old_abandoned_carts_mins_ago', 1800); // a half hour $args = array('status' => array('abandoned', 'pending'), 'start_date' => $thirty_mins_ago, 'end_date' => $time); $pending_payments = new EDD_Payments_Query($args); $payments = $pending_payments->get_payments(); if (empty($payments)) { return; } foreach ($payments as $payment) { $payment_id = $payment->ID; $user_id = edd_get_payment_user_id($payment_id); $uid = EDD_Segment_Identity::get_uid_from_user_id($user_id); $meta = edd_get_payment_meta($payment_id); // Adding an event for each item foreach ($meta['cart_details'] as $key => $item_details) { $item_details = array_merge($item_details, array('time' => time())); do_action('edd_segment_track', $uid, 'Abandoned Cart', $item_details); } } }