Plugin Directory

Changeset 2362527


Ignore:
Timestamp:
08/16/2020 07:27:13 PM (6 years ago)
Author:
creativehassan
Message:

Plugin update for product ID in PAGE_VIEW pixel fire

Location:
snap-pixel
Files:
28 added
4 edited

Legend:

Unmodified
Added
Removed
  • snap-pixel/trunk/assets/js/snapchat-pixel.js

    r2161743 r2362527  
    1 jQuery(document).ready(function($) {
    2 
    3 });
     1function get_product_record( product_id ){
     2    var $ = jQuery;
     3    var snappixel_data = 'snap_product_id='+product_id+'&action=snapchat_product_data';
     4    var return_response = '';
     5    $.ajax({
     6        action:  'snapchat_product_data',
     7        type:    "POST",
     8        url:     snappixel.ajaxurl,
     9        data:    snappixel_data,
     10        success: function( response ) {
     11            if(response.success){
     12                return_response = response.data;
     13                $("body").append("<input type='hidden' id='return_response' value='"+ return_response +"'>")
     14            }
     15        }
     16    });
     17};
  • snap-pixel/trunk/includes/function.php

    r2305256 r2362527  
    6060        public function snapchat_pixel_code_add_to_cart ($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data){
    6161            if($this->snapchat_pixel_wooacces == "yes" && $this->addtocart == "checked" && $this->snapchat_pixel_wooexist()){
     62               
    6263                $term_list = wp_get_post_terms($product_id,'product_cat',array('fields'=>'ids'));
    6364                $cat_id = (int)$term_list[0];
    6465                $category = get_term ($cat_id, 'product_cat');
    6566                $product_category = $category->name;
     67                if($variation_id){
     68                    $product_id = $variation_id;
     69                }
    6670                $_product = wc_get_product($product_id);
    6771                $product_price = $_product->get_price();
     
    102106
    103107        public function snapchat_pixel_code_everywhere (){
     108            global $post;
     109           
     110            $producted_id = "";
     111            $product_id = $post->ID;
     112            $_product = wc_get_product($product_id);
     113            if( $post && $_product && is_product() ){
     114                $producted_id = $_product->get_id();
     115                echo $producted_id;
     116            }
    104117            ?>
    105118            <script type='text/javascript'>
     
    121134              'user_email':'<?php echo $this->user_email; ?>'
    122135            })
    123               snaptr('track','PAGE_VIEW')
     136            var item_ids = <?php if($producted_id){ ?> {'item_ids': ["<?php echo $producted_id; ?>"] } <?php } else { echo "0"; } ?>;
     137            snaptr('track','PAGE_VIEW', item_ids);
    124138            </script>
    125139
     
    206220                jQuery( 'body' ).on( 'added_to_cart', function( e,h, w, button ) {
    207221                    var product_id = button.data("product_id");
    208                     snaptr('track', 'ADD_CART', {'currency': "<?php echo $product_currency;?>", 'price': "<?php echo $product_price;?>",
    209                     'item_category': "", 'item_ids': [product_id] });
     222                    var product_result = get_product_record(product_id);
     223                    var product_price = "<?php echo $product_price;?>";
     224                    setTimeout(function(){
     225                        product_price = jQuery("#return_response").val();
     226                        snaptr('track', 'ADD_CART', {'currency': "<?php echo $product_currency;?>", 'price': product_price,
     227                        'item_category': "", 'item_ids': [product_id] });
     228                    }, 1000);
    210229                 });
    211230                 // Ajax addtocart support for plugin
     
    213232                     jQuery(document).on("click", ".single_add_to_cart_button", function(){
    214233                        var product_id = jQuery('[name="product_id"]').val();
    215                         snaptr('track', 'ADD_CART', {'currency': "<?php echo $product_currency;?>", 'price': "<?php echo $product_price;?>",
    216                         'item_category': "", 'item_ids': [product_id] });
     234                        get_product_record(product_id);
     235                        var product_price = "<?php echo $product_price;?>";
     236                        setTimeout(function(){
     237                            product_price = jQuery("#return_response").val();
     238                            snaptr('track', 'ADD_CART', {'currency': "<?php echo $product_currency;?>", 'price': "<?php echo $product_price;?>",
     239                            'item_category': "", 'item_ids': [product_id] });
     240                        }, 1000);
     241                       
    217242                    });
    218243                 }
  • snap-pixel/trunk/readme.txt

    r2358797 r2362527  
    88Tested up to: 5.5
    99Requires PHP: 5.6
    10 Stable tag: 1.5.2
     10Stable tag: 1.5.3
    1111License: GPLv2 or later
    1212License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8686= 1.5.1 =
    8787* User Email is added for tracking if user is logged in.
     88= 1.5.2 =
     89* WordPress 5.5 updates
     90= 1.5.3 =
     91* Product ID is added in PAGE_VIEW and improved the product details for pixel
  • snap-pixel/trunk/snapchat-pixel.php

    r2358797 r2362527  
    44 * Plugin URI:  https://wordpress.org/plugins/snap-pixel
    55 * Description: Snapchat (Snap Pixel) to measure the cross-device impact of campaigns. It is best suited for your direct response goals, such as driving leads, Subscriptions, or product sales.
    6  * Version:     1.5.2
     6 * Version:     1.5.3
    77 * Author:      Hassan Ali
    88 * Author URI:  https://hassanali.pro
     
    3737            // Snap pixel about link on plugin row meta
    3838            add_filter( 'plugin_row_meta', array( $this, 'snapchat_pixel_row_meta' ), 10, 2 );
     39           
     40            // Snap pixel frontend js and css
     41            add_action('wp_enqueue_scripts', array( $this, 'snapchat_pixel_assets') );
    3942
    4043            //enqueue for the admin section styles and javascript
    4144            add_action('admin_enqueue_scripts', array( $this, 'admin_style_scripts' ));
     45           
     46            add_action( 'wp_ajax_nopriv_snapchat_product_data', array( $this, 'snapchat_product_data') );
     47            add_action( 'wp_ajax_snapchat_product_data', array( $this, 'snapchat_product_data') );
    4248
    4349            //language support
     
    6773            return (array) $links;
    6874        }
     75        function snapchat_pixel_assets(){
     76            wp_register_script('snap-pixel', plugin_dir_url(__FILE__) . 'assets/js/snapchat-pixel.js', array( 'jquery' ), strtotime('now'), false);
     77            wp_localize_script(
     78                'snap-pixel',
     79                'snappixel',
     80                array(
     81                  'ajaxurl' => admin_url('admin-ajax.php')
     82                )
     83            );
     84            wp_enqueue_script('snap-pixel');
     85        }
    6986        /**
    7087         * Set setting link on plugin page
     
    7895            return $links;
    7996        }
     97       
     98        function snapchat_product_data(){
     99            global $wpdb;
     100            if(isset($_REQUEST['snap_product_id']) && $_REQUEST['snap_product_id'] != ""){
     101                $snap_product_id = $_REQUEST['snap_product_id'];
     102                $_product = wc_get_product($snap_product_id);
     103                if($_product){
     104                    $product_price = $_product->get_price();
     105                }
     106                wp_send_json_success($product_price);
     107                wp_die();
     108            }
     109
     110            wp_send_json_error( "Error" );
     111            wp_die();
     112        }
     113       
    80114        /**
    81115         * Set admin notice for snap pixel id
Note: See TracChangeset for help on using the changeset viewer.