Plugin Directory

Changeset 2606796


Ignore:
Timestamp:
09/29/2021 01:36:20 PM (5 years ago)
Author:
juanin8
Message:

2.1.1

  • Fixes for Logged In event and fallback identify call
Location:
segment-for-wp-by-in8-io/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • segment-for-wp-by-in8-io/trunk/README.txt

    r2606659 r2606796  
    66Tested up to: 5.8.1
    77Requires PHP: 7.0.0
    8 Stable tag: 2.1.0
     8Stable tag: 2.1.1
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7272== Changelog ==
    7373
     74= 2.1.1 =
     75* Fixes for Logged In event and fallback identify call
     76
    7477= 2.1.0 =
    7578* Adding filter hooks and hook documentation
  • segment-for-wp-by-in8-io/trunk/includes/class-segment-for-wp-by-in8-io-identify.php

    r2606659 r2606796  
    33class Segment_For_Wp_By_In8_Io_Identify {
    44
    5     /**
    6     * The ID of this plugin.
    7     *
    8     * @since    1.0.0
    9     * @access   private
    10     * @var      string $plugin_name The ID of this plugin.
    11     */
    12     private $plugin_name;
     5    /**
     6    * The ID of this plugin.
     7    *
     8    * @since    1.0.0
     9    * @access   private
     10    * @var      string $plugin_name The ID of this plugin.
     11    */
     12    private $plugin_name;
    1313
    14     /**
    15     * The version of this plugin.
    16     *
    17     * @since    1.0.0
    18     * @access   private
    19     * @var      string $version The current version of this plugin.
    20     */
    21     private $version;
    22     /**
    23     * @var
    24     */
    25     private $settings;
     14    /**
     15    * The version of this plugin.
     16    *
     17    * @since    1.0.0
     18    * @access   private
     19    * @var      string $version The current version of this plugin.
     20    */
     21    private $version;
     22    /**
     23    * @var
     24    */
     25    private $settings;
    2626
    27     public function __construct( $plugin_name, $version, $settings ) {
    28         $this->plugin_name = $plugin_name;
    29         $this->version     = $version;
    30         $this->settings    = $settings;
    31     }
     27    public function __construct( $plugin_name, $version, $settings ) {
     28        $this->plugin_name = $plugin_name;
     29        $this->version     = $version;
     30        $this->settings    = $settings;
     31    }
    3232
    33     function render_segment_identify() {
    34         if ( isset( $_SERVER["HTTP_X_REQUESTED_WITH"] ) ) { //Only render these for actual browsers
    35             return;
    36         }
     33    function render_segment_identify() {
     34        if ( isset( $_SERVER["HTTP_X_REQUESTED_WITH"] ) ) { //Only render these for actual browsers
     35            return;
     36        }
    3737
    38         if (Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'identify' ) || Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'wp_logout' ) ) {
    39             $settings = $this->settings;
    40             if ( isset( $settings['js_api_key'] ) && $settings['js_api_key'] !== '' && $settings['js_api_key'] !== null ) {
    41                 $current_user   = wp_get_current_user();
    42                 $current_post   = get_post();
    43                 $trackable_user = Segment_For_Wp_By_In8_Io::check_trackable_user( $current_user );
    44                 $trackable_post = Segment_For_Wp_By_In8_Io::check_trackable_post( $current_post );
    45                 if ( $trackable_user && $trackable_post ) {
    46                     if ( Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'identify' ) ) {
    47                         $cookie_data = Segment_For_Wp_By_In8_Io_Cookie::get_cookie( 'identify' );
    48                         $cookie_name = Segment_For_Wp_By_In8_Io_Cookie::get_cookie_name( 'identify' );
    49                         $user_info   = Segment_For_Wp_By_In8_Io::get_user_info_from_cookie( $cookie_data, $cookie_name );
    50                         $wp_user_id  = $user_info["wp_user_id"];
    51                         $user_id     = $user_info['user_id'];
    52                         if ( ! isset( $wp_user_id ) || ! isset( $user_id ) || $wp_user_id == null || $wp_user_id == 0 ) {
    53                             ?>
     38        if (Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'identify' ) || Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'wp_logout' ) ) {
     39            $settings = $this->settings;
     40            if ( isset( $settings['js_api_key'] ) && $settings['js_api_key'] !== '' && $settings['js_api_key'] !== null ) {
     41                $current_user   = wp_get_current_user();
     42                $current_post   = get_post();
     43                $trackable_user = Segment_For_Wp_By_In8_Io::check_trackable_user( $current_user );
     44                $trackable_post = Segment_For_Wp_By_In8_Io::check_trackable_post( $current_post );
     45                if ( $trackable_user && $trackable_post ) {
     46                    if ( Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'identify' ) ) {
     47                        $cookie_data = Segment_For_Wp_By_In8_Io_Cookie::get_cookie( 'identify' );
     48                        $cookie_name = Segment_For_Wp_By_In8_Io_Cookie::get_cookie_name( 'identify' );
     49                        $user_info   = Segment_For_Wp_By_In8_Io::get_user_info_from_cookie( $cookie_data, $cookie_name );
     50                        $wp_user_id  = $user_info["wp_user_id"];
     51                        $user_id     = $user_info['user_id'];
     52                        if ( ! isset( $wp_user_id ) || ! isset( $user_id ) || $wp_user_id == null || $wp_user_id == 0 ) {
     53                            ?>
    5454                            <script type="text/javascript">
    5555                                Cookies.remove("<?php echo sanitize_text_field( $cookie_name )?>");
    5656                            </script>
    57                             <?php
    58                             Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
    59                             return;
    60                         }
     57                            <?php
     58                            Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
     59                            return;
     60                        }
    6161
    62                         $traits = Segment_For_Wp_By_In8_Io::get_user_traits( $wp_user_id );
     62                        $traits = Segment_For_Wp_By_In8_Io::get_user_traits( $wp_user_id );
    6363                        $traits = array_filter($traits);
    6464                        $traits = apply_filters('segment_for_wp_change_user_traits', $traits, $user_info);
    6565                        $user_id = apply_filters('segment_for_wp_change_user_id', $user_id);
    6666
    67                         ?>
     67                        ?>
    6868                        <script type="text/javascript">
    6969                            console.log(<?php echo sanitize_text_field( json_encode( $traits ) )?>)
    7070                            analytics.identify("<?php echo sanitize_text_field(  $user_id ) ?>",
    71                                 <?php echo json_encode( $traits ) ?>,
     71                                <?php echo json_encode( $traits ) ?>,
    7272                                {},
    7373                                function () {
     
    7676                            );
    7777                        </script>
    78                         <?php
    79                         Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
     78                        <?php
     79                        Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
    8080
    81                     }
     81                    }
    8282
    8383                    else {
    84                         $wp_user_id = $current_user->ID;
    85                         if ( $wp_user_id && $wp_user_id != 0 ) {
    86                             $user_id = Segment_For_Wp_By_In8_Io::get_user_id( $wp_user_id );
    87                             if ( $user_id && $user_id !== 0 ) {
    88                                 $traits = Segment_For_Wp_By_In8_Io::get_user_traits( $wp_user_id );
     84                        $wp_user_id = $current_user->ID;
     85                        if ( $wp_user_id && $wp_user_id != 0 ) {
     86                            $user_id = Segment_For_Wp_By_In8_Io::get_user_id( $wp_user_id );
     87                            if ( $user_id && $user_id !== 0 ) {
     88                                $traits = Segment_For_Wp_By_In8_Io::get_user_traits( $wp_user_id );
    8989                                $traits = array_filter($traits);
    9090                                $traits = apply_filters('segment_for_wp_change_user_traits', $traits, $current_user);
    9191                                $user_id = apply_filters('segment_for_wp_change_user_id', $user_id);
    92                                 ?>
     92                                ?>
    9393                                <script type="text/javascript">
    9494                                    analytics.identify("<?php echo sanitize_text_field( $user_id ) ?>",
    95                                         <?php echo sanitize_text_field( json_encode( $traits ) )?>,
     95                                        <?php echo sanitize_text_field( json_encode( $traits ) )?>,
    9696                                    );
    9797                                </script>
    98                                 <?php
    99                             }
    100                         }
    101                     }
    102                 }
    103                 if (Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'wp_logout' )) {
    104                     $cookie_name = Segment_For_Wp_By_In8_Io_Cookie::get_cookie_name( 'wp_logout' );
    105                     Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
    106                 }
    107             }
    108         }
     98                                <?php
     99                            }
     100                        }
     101                    }
     102                }
     103                if (Segment_For_Wp_By_In8_Io_Cookie::check_cookie( 'wp_logout' )) {
     104                    $cookie_name = Segment_For_Wp_By_In8_Io_Cookie::get_cookie_name( 'wp_logout' );
     105                    Segment_For_Wp_By_In8_Io_Cookie::delete_matching_cookies($cookie_name);
     106                }
     107            }
     108        }
     109        else{
     110            if(is_user_logged_in() && !isset($_COOKIE["ajs_user_id"])) {
    109111
    110     }
     112                if ( isset( $settings['js_api_key'] ) && $settings['js_api_key'] !== '' && $settings['js_api_key'] !== null ) {
     113                    $current_user   = wp_get_current_user();
     114                    $current_post   = get_post();
     115                    $trackable_user = Segment_For_Wp_By_In8_Io::check_trackable_user( $current_user );
     116                    $trackable_post = Segment_For_Wp_By_In8_Io::check_trackable_post( $current_post );
     117                    if ( $trackable_user && $trackable_post ) {
     118                            $wp_user_id  = get_current_user_id();
     119                            $user_id     = Segment_For_Wp_By_In8_Io::get_user_id($wp_user_id);
     120                            $traits = Segment_For_Wp_By_In8_Io::get_user_traits( $wp_user_id );
     121                            $traits = array_filter($traits);
     122                            $traits = apply_filters('segment_for_wp_change_user_traits', $traits, $current_user);
     123                            $user_id = apply_filters('segment_for_wp_change_user_id', $user_id);
     124
     125                            ?>
     126                            <script type="text/javascript">
     127                                console.log(<?php echo sanitize_text_field( json_encode( $traits ) )?>)
     128                                analytics.identify("<?php echo sanitize_text_field(  $user_id ) ?>",
     129                                    <?php echo json_encode( $traits ) ?>,
     130                                    {},
     131                                    function () {
     132                                    }
     133                                );
     134                            </script>
     135                            <?php
     136
     137                    }
     138                }
     139
     140            }
     141
     142        }
     143
     144    }
    111145
    112146}
  • segment-for-wp-by-in8-io/trunk/includes/class-segment-for-wp-by-in8-io.php

    r2606659 r2606796  
    284284
    285285        //LOGINS
    286         if (array_key_exists('track_ninja_forms_fieldset', $settings)) {
     286        if (array_key_exists('track_logins_fieldset', $settings)) {
    287287            if ($settings["track_logins_fieldset"]["track_logins"] == "yes") {
    288288                $this->loader->add_action('wp_login', $plugin_public, 'wp_login', 1, 2);
  • segment-for-wp-by-in8-io/trunk/segment-for-wp-by-in8-io.php

    r2606659 r2606796  
    1010 * Plugin URI:        https://github.com/omgwtfwow/segment-for-wp-by-in8-io
    1111 * Description:       Segment Analytics for WordPress
    12  * Version:           2.1.0
     12 * Version:           2.1.1
    1313 * Author:            Juan
    1414 * Author URI:        https://juangonzalez.com.au
     
    2727 * Currently plugin version.
    2828 */
    29 define( 'SEGMENT_FOR_WP_BY_IN8_IO_VERSION', '2.1.0' );
     29define( 'SEGMENT_FOR_WP_BY_IN8_IO_VERSION', '2.1.1' );
    3030
    3131/**
Note: See TracChangeset for help on using the changeset viewer.