Plugin Directory

Changeset 1927465


Ignore:
Timestamp:
08/20/2018 03:40:51 PM (8 years ago)
Author:
pepperjam2016
Message:

Added first party cookie support for Safari ITP 2.0

Location:
pepperjam-pixel/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pepperjam-pixel/trunk/includes/class-pj-pixel-integration.php

    r1511998 r1927465  
    7878        // Tracking code
    7979        add_action( 'wp_footer', array( $this, 'maybe_display_pj_pixel' ), 99 );
     80
     81        // Manage click_id cookie
     82        add_action('init', array($this, 'maybe_write_click_id_cookie'));
    8083
    8184        // Test mode meta box for orders
     
    234237        echo $pixel;
    235238    }
     239
     240    public function maybe_write_click_id_cookie()
     241    {
     242        $url_params = array_change_key_case($_GET);
     243        if(isset($url_params[PJ_CLICKID_URL_PARAM]))
     244        {
     245            $click_id = $url_params[PJ_CLICKID_URL_PARAM];
     246            $click_ids = array();
     247
     248            if(isset($_COOKIE[PJ_CLICK_ID_COOKIE]))
     249            {
     250                $click_ids = $this->get_click_id_cookie_as_array();
     251            }
     252
     253            // Put click id into an associative array so that any existing click id with the same value is overwritten
     254            $click_ids[$click_id] = array('timestamp' => time(), 'click_id' => $click_id);
     255
     256            $cookie_expiration_unix_time = time()+60*60*24*365*10; // 10 year expiration (more or less)
     257            setcookie(PJ_CLICK_ID_COOKIE, json_encode($click_ids), $cookie_expiration_unix_time, '/');
     258        }
     259    }
     260
     261    public static function get_click_id_cookie_as_array()
     262    {
     263        return json_decode(stripslashes($_COOKIE[PJ_CLICK_ID_COOKIE]), true);
     264    }
    236265}
  • pepperjam-pixel/trunk/includes/class-pj-pixel.php

    r1753433 r1927465  
    164164        $this->integration_type = isset( $options['pj_integration_type'] )  ? $options['pj_integration_type']   : '';
    165165        $this->tracking_url     = isset( $options['pj_tracking_url'] )      ? $options['pj_tracking_url']       : '';
     166        $this->lookback_days    = isset( $options['pj_lookback_days'] )     ? $options['pj_lookback_days']      : 60;
    166167        $this->date_implemented = isset( $options['pj_date_implemented'] )  ? $options['pj_date_implemented']   : '';
    167168        $this->_is_testmode = ( isset( $options['pj_testmode'] ) && 'yes' === $options['pj_testmode'] );
     
    193194            // Process Order Data
    194195            $order_params = $this->_process_order_data();
     196
     197            // Get comma delimited string of stored click_ids created within the lookback period
     198            $click_ids_in_cookie = PJ_Pixel_Integration::get_click_id_cookie_as_array();
     199            if(isset($click_ids_in_cookie))
     200            {
     201                $cutoffTimestamp = time() - 60*60*24*$this->lookback_days;
     202                $click_id_params = array();
     203                foreach($click_ids_in_cookie as $click_id => $data)
     204                {
     205                    if($data['timestamp'] > $cutoffTimestamp)
     206                    {
     207                        $click_id_params[] = $click_id;
     208                    }
     209                }
     210                $base_params['CLICK_ID'] = implode(",", $click_id_params);
     211            }
    195212
    196213            // Merge data
  • pepperjam-pixel/trunk/includes/data-pj-form-fields.php

    r1511998 r1927465  
    3131        'default'       => 'https://t.pepperjamnetwork.com'
    3232    ),
     33    'pj_lookback_days' => array(
     34        'title'         => __( 'Lookback period', 'pepperjam' ),
     35        'description'   =>  __( 'Number of days.', 'pepperjam' ),
     36        'type'          => 'text',
     37        'options'       => array(
     38            'https://t.pepperjamnetwork.com' => 'https://t.pepperjamnetwork.com'
     39        ),
     40        'default'       => '60'
     41    ),
    3342    'pj_date_implemented' => array(
    3443        'title'         => __( 'Program Implementation Date', 'pepperjam' ),
  • pepperjam-pixel/trunk/pepperjam.php

    r1753433 r1927465  
    44 * Plugin URI: https://www.pepperjam.com/
    55 * Description: Extend the WooCommerce platform with Pepperjam pixel.
    6  * Version: 1.0.8
     6 * Version: 1.0.9
    77 * Author: Brad Cavanaugh <bradkcavanaugh@gmail.com>
    88 * Author URI: https://bradkcavanaugh.com
     
    125125        $this->define( 'PJ_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    126126        $this->define( 'PJ_LOG_DIR', $upload_dir['basedir'] . '/pj-logs/' );
    127     }
    128 
    129     /**
     127        $this->define( 'PJ_CLICK_ID_COOKIE', 'pepperjam_click_ids' );
     128        $this->define( 'PJ_CLICKID_URL_PARAM', 'clickid' );
     129    }
     130
     131    /**
    130132     * Define constant if not already set.
    131133     *
  • pepperjam-pixel/trunk/readme.txt

    r1753433 r1927465  
    33Tags: WooCommerce, Pepperjam, Pixel, Woo, Commerce
    44Requires at least: 3.0.1
    5 Tested up to: 4.8.1
     5Tested up to: 4.9.8
    66Stable tag: trunk
    77License: GPLv2 or later
     
    2222
    23231. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
    24 1. Activate the plugin through the 'Plugins' screen in WordPress.
    25 1. Use the WooCommerce->Settings->Integration->Pepperjam Pixel screen to configure the plugin.
    26 1. Enter the 'Program ID' as provided by your Pepperjam Account manager.
    27 1. Select the 'Integration Type' as provided by your Pepperjam Account manager.
    28 1. Select the 'Tracking Url' as provided by your Pepperjam Account manager.
    29 1. (optional) Set the 'Program Implementation Date'.  If you are unsure of what date to use, consult with your Pepperjam Account manager.
     242. Activate the plugin through the 'Plugins' screen in WordPress.
     253. Use the WooCommerce->Settings->Integration->Pepperjam Pixel screen to configure the plugin.
     264. Enter the 'Program ID' as provided by your Pepperjam Account manager.
     275. Select the 'Integration Type' as provided by your Pepperjam Account manager.
     286. Select the 'Tracking Url' as provided by your Pepperjam Account manager.
     297. Set the lookback period as provided by your Pepperjam Account manager.
     308. (optional) Set the 'Program Implementation Date'.  If you are unsure of what date to use, consult with your Pepperjam Account manager.
    3031
    3132== Changelog ==
     33
     34= 1.0.9 =
     35* Added first party cookie support for Safari ITP 2.0
    3236
    3337= 1.0.8 =
Note: See TracChangeset for help on using the changeset viewer.