public static function new_uninstall($props = array())
 {
     $user_id = EDD_Segment_Identity::get_uid($props['email']);
     // Send identity
     $traits = array('name' => isset($props['name']) ? $props['name'] : '', 'email' => $props['email']);
     do_action('edd_segment_identify', $user_id, $traits);
     // Send event
     $event_props = array('name' => 'sprout-invoices', 'time' => time(), 'email' => $props['email'], 'uninstall_code' => $props['uninstall_code'], 'uninstall_reason' => $props['uninstall_reason'], 'site_url' => $props['site_url']);
     do_action('edd_segment_track', $user_id, 'Free Uninstall', $event_props);
 }
Example #2
0
/**
 * Load the SI application
 * (function called at the bottom of this page)
 *
 * @package EDD_Segment
 * @return void
 */
function edd_segment_load()
{
    if (class_exists('EDD_Segment')) {
        edd_segment_deactivate_plugin();
        return;
        // already loaded, or a name collision
    }
    do_action('edd_segment_preload');
    //////////
    // Load //
    //////////
    // Master class
    require_once EDD_SEGMENT_PATH . '/Segment.php';
    // controllers
    require_once EDD_SEGMENT_PATH . '/controllers/_Controller.php';
    EDD_Segment_Controller::init();
    if (!class_exists('SA_Settings_API')) {
        require_once EDD_SEGMENT_PATH . '/controllers/_Settings.php';
        SA_Settings_API::init();
    }
    require_once EDD_SEGMENT_PATH . '/controllers/Settings.php';
    EDD_Segment_Settings::init();
    require_once EDD_SEGMENT_PATH . '/controllers/Identity.php';
    EDD_Segment_Identity::init();
    require_once EDD_SEGMENT_PATH . '/controllers/integrations/Segment_API.php';
    EDD_Segment_Tracker::init();
    require_once EDD_SEGMENT_PATH . '/controllers/integrations/CustomerIO_API.php';
    EDD_CustomerIO_Tracker::init();
    if (file_exists(EDD_SEGMENT_PATH . '/controllers/add-ons/AJAX_Callbacks.php')) {
        require_once EDD_SEGMENT_PATH . '/controllers/add-ons/AJAX_Callbacks.php';
        EDD_Segment_AJAX_Callbacks::init();
    }
    if (file_exists(EDD_SEGMENT_PATH . '/controllers/add-ons/Freemius_Webhook.php')) {
        require_once EDD_SEGMENT_PATH . '/controllers/add-ons/Freemius_Webhook.php';
        EDD_Segment_Freemius_Webhook::init();
    }
    require_once EDD_SEGMENT_PATH . '/controllers/add-ons/EDD_Hooks.php';
    EDD_Segment_Hooks::init();
    require_once EDD_SEGMENT_PATH . '/controllers/Updates.php';
    EDD_Segment_Updates::init();
    require_once EDD_SEGMENT_PATH . '/template-tags/edd-segment.php';
    do_action('edd_segment_loaded');
}
Example #3
0
 /**
  * Used from an external API call to wp admin ajax to register a user
  * and create a new segment identity.
  *
  */
 public static function maybe_free_license_registration()
 {
     if (!isset($_REQUEST['uid'])) {
         self::ajax_fail('No uid submitted');
     }
     $email = $_REQUEST['uid'];
     if (!is_email($email)) {
         self::ajax_fail('uid not valid');
     }
     $user_id = EDD_Segment_Identity::get_uid($email);
     // Send identity
     $traits = array('name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : '', 'email' => $email, 'website' => isset($_REQUEST['url']) ? $_REQUEST['url'] : '');
     do_action('edd_segment_identify', $user_id, $traits);
     // Send event
     $props = array('name' => isset($_REQUEST['item_name']) ? $_REQUEST['item_name'] : '', 'url' => isset($_REQUEST['url']) ? $_REQUEST['url'] : '', 'time' => time(), 'email' => $email);
     do_action('edd_segment_track', $user_id, 'Free Product Registration', $props);
     // The response sends the user's license key,
     // which at this moment is just a random string
     // that isn't yet tied to the user.
     $response = array('license_key' => wp_generate_password(40, false), 'uid' => $user_id);
     header('Content-type: application/json');
     echo json_encode($response);
     exit;
 }
Example #4
0
    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 
    }
Example #5
0
 /**
  * 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);
         }
     }
 }