Changeset 2988403
- Timestamp:
- 11/03/2023 10:03:17 AM (2 years ago)
- Location:
- releva-nz/trunk
- Files:
-
- 3 deleted
- 7 edited
-
README.txt (modified) (2 diffs)
-
admin/class-relevatracking-admin.php (modified) (3 diffs)
-
admin/partials/admin-menu.php (modified) (1 diff)
-
admin/partials/relevatracking-admin-display.php (deleted)
-
includes/class-relevatracking.php (modified) (1 diff)
-
public/class-relevatracking-public.php (modified) (22 diffs)
-
public/js/relevatracking-public.js (modified) (1 diff)
-
public/partials/front-page.php (deleted)
-
public/partials/relevatracking-public-display.php (deleted)
-
relevatracking.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
releva-nz/trunk/README.txt
r2747436 r2988403 3 3 Tags: e-commerce, sales, advertising, marketing, retargeting, remarketing 4 4 Requires at least: 3.0.1 5 Tested up to: 6. 0.05 Tested up to: 6.4.0 6 6 Requires PHP: 5.2 7 7 Stable tag: trunk … … 70 70 = 2.1.3 = 71 71 * add pagination for large product exports for better performance 72 73 = 2.1.4 = 74 * improved tracking for custom success pages -
releva-nz/trunk/admin/class-relevatracking-admin.php
r2369532 r2988403 107 107 { 108 108 foreach ($this->options as $option) { 109 register_setting($this->get_id() . '_group', $this->get_id() . '_' . $option['name'], array($this, 'api_opt_validate')); 110 } 111 } 109 if($option['name'] === 'api_key') { 110 register_setting($this->get_id() . '_group', $this->get_id() . '_' . $option['name'], array($this, 'api_opt_validate')); 111 } else { 112 register_setting($this->get_id() . '_group', $this->get_id() . '_' . $option['name'], array($this, 'store_setting')); 113 } 114 } 115 } 116 117 public function store_setting($input) 118 { 119 return $input; 120 } 112 121 113 122 public function api_opt_validate($input) 114 123 { 124 115 125 $api_key_post = sanitize_text_field($this->butler_post('relevatracking_api_key')); 116 126 … … 169 179 $option['value'] = get_option($option['id']); 170 180 $this->options[$option['id']] = $option; 181 182 $option2 = array(); 183 $option2['name'] = 'additional_html'; 184 $option2['id'] = $this->get_id() . '_' . $option2['name']; 185 $option2['type'] = 'textarea'; 186 $option2['label'] = __('Additional HTML', $this->plugin_name); 187 $option2['hint'] = __('', $this->plugin_name); 188 $option2['value'] = get_option($option2['id']); 189 $this->options[$option2['id']] = $option2; 171 190 } 172 191 … … 176 195 // Add your own main menu item 177 196 // Releva tracking 178 add_menu_page(197 add_menu_page( 179 198 __('releva.nz', $this->plugin_name), 180 199 __('releva.nz', $this->plugin_name), 181 200 'manage_options', 182 201 $this->get_id() . '_menu', 183 array($this, 'render_admin_ menu'),202 array($this, 'render_admin_chart'), 184 203 'dashicons-screenoptions', 185 204 self::MENU_POSITION 186 205 ); 187 206 188 add_submenu_page($this->get_id() . '_menu', __('Settings', $this->plugin_name), __('Settings', $this->plugin_name), 'manage_options', $this->get_id() . '_menu');189 190 207 add_submenu_page( 191 208 $this->get_id() . '_menu', 192 __(' releva.nz', $this->plugin_name),193 __(' releva.nz', $this->plugin_name),209 __('Settings', $this->plugin_name), 210 __('Settings', $this->plugin_name), 194 211 'manage_options', 195 $this->get_id() . '_ chart',196 array($this, 'render_admin_ chart')212 $this->get_id() . '_settings', 213 array($this, 'render_admin_menu') 197 214 ); 198 215 } -
releva-nz/trunk/admin/partials/admin-menu.php
r2369532 r2988403 20 20 _e( 'Settings', $this->plugin_name) ?></h3> 21 21 </p> 22 23 <p style="display:none"><strong><?php _e( 'Link to export products', $this->plugin_name ); ?></strong>: <span style="color:#005ebb"><?php echo home_url() ; ?><strong>/?releva_action=jsonexport</strong></span></p><hr />24 22 25 23 <?php if ( $this->options ): ?> -
releva-nz/trunk/includes/class-relevatracking.php
r2747436 r2988403 70 70 71 71 $this->plugin_name = 'relevatracking'; 72 $this->version = '2.1. 3';72 $this->version = '2.1.5'; 73 73 74 74 $this->load_dependencies(); -
releva-nz/trunk/public/class-relevatracking-public.php
r2747436 r2988403 21 21 * @author Relevanz <tec@releva.nz> 22 22 */ 23 class Relevatracking_Public { 23 class Relevatracking_Public 24 { 24 25 25 26 /** … … 48 49 * @param string $version The version of this plugin. 49 50 */ 50 public function __construct( $plugin_name, $version ) { 51 public function __construct($plugin_name, $version) 52 { 51 53 52 54 $this->plugin_name = $plugin_name; 53 55 $this->version = $version; 56 54 57 // Is there a client_id ? 55 58 //$this->load_client_id(); 56 59 $this->client_id = self::load_client_id(); 57 60 58 add_action( 'releva_csvexport', array( $this, 'csvexport' ) ); 59 add_action( 'releva_callback', array( $this, 'callback' ) ); 60 61 } 62 63 //const RELEVATRC_KEY_URL = 'http://api.hyj.mobi/user/get'; 61 add_action('releva_csvexport', array($this, 'csvexport')); 62 add_action('releva_callback', array($this, 'callback')); 63 64 65 add_action('woocommerce_before_thankyou', array($this, 'retargeting_confirmation'), 40); 66 } 67 64 68 protected $apikey; 65 69 protected static $cache = array(); 66 70 67 public static function load_client_id() { 68 69 /* 70 $this->client_id = (string)get_option( $this->plugin_name . '_client_id' ); 71 if(empty($this->client_id)) { 72 73 } 74 */ 75 76 $apikey = (string)get_option( 'relevatracking_api_key' ); 71 public static function load_client_id() 72 { 73 $apikey = (string)get_option('relevatracking_api_key'); 77 74 $storeId = md5(__METHOD__ . "::client_id::" . $apikey); 78 75 79 80 if (!isset(self::$cache[$storeId])){ 81 82 if($apikey) { 83 84 $queryParams['apikey'] = $apikey; 85 $url='https://backend.releva.nz/v1/campaigns/get'; 86 $connectUrl = $url. '?' . http_build_query($queryParams); 87 $data = self::getUrl($connectUrl, 5); 88 89 $response=self::arrayGetValue($data, 'response'); 90 $response = json_decode ($response) ; 91 92 if(!empty($response) && is_object($response) && isset($response->user_id)) { 93 self::$cache[$storeId] = $response->user_id; 94 } 95 96 } 97 98 } 99 100 if (isset(self::$cache[$storeId])){ 101 return self::$cache[$storeId] ; 76 if (!isset(self::$cache[$storeId])) { 77 78 if ($apikey) { 79 $queryParams['apikey'] = $apikey; 80 $url = 'https://backend.releva.nz/v1/campaigns/get'; 81 $connectUrl = $url . '?' . http_build_query($queryParams); 82 $data = self::getUrl($connectUrl, 5); 83 84 $response = self::arrayGetValue($data, 'response'); 85 $response = json_decode($response); 86 87 if (!empty($response) && is_object($response) && isset($response->user_id)) { 88 self::$cache[$storeId] = $response->user_id; 89 } 90 } 91 } 92 93 if (isset(self::$cache[$storeId])) { 94 return self::$cache[$storeId]; 102 95 } else { 103 96 return 0; 104 97 } 105 106 } 107 108 109 110 public function releva_init_action(){ 111 //releva_action=jsonexport 112 $releva_action = isset($_GET['releva_action'])?$_GET['releva_action']:''; 113 //echo "<pre>"; var_export($releva_action); echo "</pre>"; 114 // exit; 115 if($releva_action) { 116 $releva_action = preg_replace('/\W/', '', $releva_action); 117 do_action('releva_'.$releva_action); 118 } 119 } 120 121 public function getPhpVersion() { 98 } 99 100 public function releva_init_action() 101 { 102 $releva_action = isset($_GET['releva_action']) ? $_GET['releva_action'] : ''; 103 if ($releva_action) { 104 $releva_action = preg_replace('/\W/', '', $releva_action); 105 do_action('releva_' . $releva_action); 106 } 107 } 108 109 public function getPhpVersion() 110 { 122 111 return [ 123 112 'version' => phpversion(), 124 113 'sapi-name' => php_sapi_name(), 125 'memory-limit' => ini_get( 'memory_limit'),126 'max-execution-time' => ini_get( 'max_execution_time'),114 'memory-limit' => ini_get('memory_limit'), 115 'max-execution-time' => ini_get('max_execution_time'), 127 116 ]; 128 117 } 129 118 130 public function getDbVersion() { 119 public function getDbVersion() 120 { 131 121 global $wpdb; 132 122 133 $version_comment = $wpdb->get_var( 'SELECT @@version_comment AS `server`');123 $version_comment = $wpdb->get_var('SELECT @@version_comment AS `server`'); 134 124 return [ 135 //'version' => $wpdb->db_server_info(),136 125 'server' => $version_comment, 137 126 ]; 138 127 } 139 128 140 public function getServerEnvironment() { 129 public function getServerEnvironment() 130 { 141 131 return [ 142 'server-software' => isset( $_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null,132 'server-software' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null, 143 133 'php' => $this->getPhpVersion(), 144 134 'db' => $this->getDbVersion(), … … 146 136 } 147 137 148 public function getCallbacks() { 138 public function getCallbacks() 139 { 149 140 return [ 150 141 'callback' => [ … … 167 158 } 168 159 169 public function callback() {170 $apikey = (string)get_option( 'relevatracking_api_key' );171 $ client_id = (string)get_option( 'relevatracking_client_id');172 $ auth = isset($_GET['auth'])?$_GET['auth']:'';173 $ page = isset($_GET['page'])?$_GET['page']:0;174 175 if( $auth != md5( $apikey.':'.$client_id ) ) 176 {160 public function callback() 161 { 162 $apikey = (string)get_option('relevatracking_api_key'); 163 $client_id = (string)get_option('relevatracking_client_id'); 164 $auth = isset($_GET['auth']) ? $_GET['auth'] : ''; 165 $page = isset($_GET['page']) ? $_GET['page'] : 0; 166 167 if ($auth != md5($apikey . ':' . $client_id)) { 177 168 exit; 178 169 } … … 184 175 185 176 $wc_version = ''; 186 if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) 187 { 177 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 188 178 $wc_version = WC_VERSION; 189 179 } … … 197 187 'callbacks' => $this->getCallbacks(), 198 188 ]; 199 echo json_encode( $callback);189 echo json_encode($callback); 200 190 201 191 echo ob_get_clean(); … … 204 194 205 195 206 public function csvexport() { 207 $apikey = (string)get_option( 'relevatracking_api_key' ); 208 $client_id = (string)get_option( 'relevatracking_client_id' ); 209 $auth = isset($_GET['auth'])?$_GET['auth']:''; 210 $page = isset($_GET['page'])?$_GET['page']:0; 211 $limit = isset($_GET['limit'])?$_GET['limit']:500; 212 213 if( $auth != md5( $apikey.':'.$client_id ) ) 214 { 196 public function csvexport() 197 { 198 $apikey = (string)get_option('relevatracking_api_key'); 199 $client_id = (string)get_option('relevatracking_client_id'); 200 201 $auth = isset($_GET['auth']) ? $_GET['auth'] : ''; 202 $page = isset($_GET['page']) ? $_GET['page'] : 0; 203 $limit = isset($_GET['limit']) ? $_GET['limit'] : 500; 204 205 if ($auth != md5($apikey . ':' . $client_id)) { 215 206 exit; 216 207 } 217 208 218 $args = array( 219 'status' => 'publish', 220 'limit' => -1, 221 'orderby' => 'id', 209 $args = array( 210 'status' => 'publish', 211 'limit' => -1, 212 'orderby' => 'id', 222 213 'order' => 'asc' 223 214 ); 224 215 225 /* 226 $args = array( 227 'post_status' => array('publish'), 228 'fields' => 'ids', 229 'posts_per_page'=> -1, 230 'post_type' => array('product'), 231 'orderby' => 'id', 232 'order' => 'asc', 233 ); 234 */ 235 236 if( $page > 0 ) 237 { 216 if ($page > 0) { 238 217 $args['limit'] = $limit; 239 218 $args['page'] = $page; 240 219 } 241 220 242 $products = wc_get_products( $args);243 244 if (count($products) == 0) {221 $products = wc_get_products($args); 222 223 if (count($products) == 0) { 245 224 header('HTTP/1.0 404 Not Found'); 246 exit; 225 exit; 247 226 } 248 227 … … 255 234 256 235 header('Content-Type: text/csv'); 257 header('X-Relevanz-Product-Count: '.$the_query->found_posts);236 //header('X-Relevanz-Product-Count: ' . $the_query->found_posts); 258 237 $op = fopen("php://output", "wb"); 259 $header = ['id', 'categoryIds','name','descriptionShort','descriptionLong','price','priceOffer','link','image','lastUpdate'];238 $header = ['id', 'categoryIds', 'name', 'descriptionShort', 'descriptionLong', 'price', 'priceOffer', 'priceNet', 'priceNetOffer', 'link', 'image', 'lastUpdate']; 260 239 fputcsv($op, $header, ',', '"'); 261 240 262 263 //while ( $the_query->have_posts() ) { 264 //$the_query->the_post(); 265 foreach ($products as $p) { 266 $product_id = $p->id; 267 //$the_query->post->ID = $product_id 268 269 $single_product = array(); 270 $product = wc_get_product($product_id); 271 if(empty($product) ) { 272 continue; 241 foreach ($products as $p) { 242 $product_id = $p->id; 243 244 $single_product = array(); 245 $product = wc_get_product($product_id); 246 247 if (empty($product)) { 248 continue; 249 } 250 251 $single_product['id'] = $product_id; 252 253 $post_categories = wp_get_post_terms($product_id, $taxonomy = 'product_cat'); 254 $cat = ''; 255 $ii = 0; 256 foreach ((array)$post_categories as $post_category) : 257 if ($ii > 0) { 258 $cat .= ','; 273 259 } 274 $single_product['id'] = $product_id; 275 //$single_product['product_id'] = $product->get_id(); 276 277 $post_categories = wp_get_post_terms($product_id, $taxonomy = 'product_cat'); 278 $cat = ''; $ii = 0; 279 foreach((array)$post_categories as $post_category): 280 if($ii > 0){$cat .= ',';} 281 //$cat .= $post_category->name; 282 $cat .= $post_category->term_id; 283 $ii++; 284 endforeach; 285 $single_product['categoryIds'] = $cat; 286 287 $single_product['name'] = $product->get_name(); 288 $single_product['descriptionShort'] = $product->get_short_description(); 289 //$single_product['descriptionLong'] = $product->get_description(); 290 $single_product['descriptionLong'] = ''; 291 292 293 $single_product['price'] = wc_get_price_including_tax( $product, array('price' => $product->get_regular_price() ) ); 294 //number_format( floatval( get_post_meta( $product_id, '_regular_price', true ) ), 2, '.', '' ); 295 $single_product['priceOffer'] = wc_get_price_including_tax( $product, array('price' => $product->get_sale_price() ) ); 296 //( get_post_meta( $product_id, '_sale_price', true ) ? number_format( floatval( get_post_meta( $product_id, '_sale_price', true ) ), 2, '.', '' ) : number_format( floatval( get_post_meta( $product_id, '_regular_price', true ) ), 2, '.', '' ) ); 297 298 $single_product['link'] = $product->get_permalink(); 299 300 $single_product['image'] = $this->get_images( $product )[0]; 301 302 $lastUpdate = get_the_modified_time( 'U', $product_id ); 303 if( empty( $lastUpdate ) ) 304 { 305 $lastUpdate = get_the_time( 'U', $product_id ); 306 } 307 $single_product['lastUpdate'] = $lastUpdate; 308 309 fputcsv( $op, $single_product, ',', '"' ); 310 } 260 $cat .= $post_category->term_id; 261 $ii++; 262 endforeach; 263 $single_product['categoryIds'] = $cat; 264 265 $single_product['name'] = $product->get_name(); 266 $single_product['descriptionShort'] = $product->get_short_description(); 267 $single_product['descriptionLong'] = ''; 268 269 270 $single_product['price'] = wc_get_price_including_tax($product, array('price' => $product->get_regular_price())); 271 $single_product['priceOffer'] = wc_get_price_including_tax($product, array('price' => $product->get_sale_price())); 272 $single_product['priceNet'] = wc_get_price_excluding_tax($product, array('price' => $product->get_regular_price())); 273 $single_product['priceNetOffer'] = wc_get_price_excluding_tax($product, array('price' => $product->get_sale_price())); 274 275 $single_product['link'] = $product->get_permalink(); 276 277 $single_product['image'] = $this->get_images($product)[0]; 278 279 $lastUpdate = get_the_modified_time('U', $product_id); 280 if (empty($lastUpdate)) { 281 $lastUpdate = get_the_time('U', $product_id); 282 } 283 $single_product['lastUpdate'] = $lastUpdate; 284 285 fputcsv($op, $single_product, ',', '"'); 286 } 311 287 312 288 fclose($op); … … 323 299 * @return array 324 300 */ 325 private function get_images( $product ) { 301 private function get_images($product) 302 { 326 303 $images = $attachment_ids = array(); 327 304 $product_image = $product->get_image_id(); 328 305 329 306 // Add featured image. 330 if ( ! empty( $product_image )) {307 if (!empty($product_image)) { 331 308 $attachment_ids[] = $product_image; 332 309 } 333 310 334 311 // add gallery images. 335 $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids());312 $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); 336 313 337 314 // Build image data. 338 foreach ( $attachment_ids as $position => $attachment_id) {339 340 $attachment_post = get_post( $attachment_id);341 342 if ( is_null( $attachment_post )) {315 foreach ($attachment_ids as $position => $attachment_id) { 316 317 $attachment_post = get_post($attachment_id); 318 319 if (is_null($attachment_post)) { 343 320 continue; 344 321 } 345 322 346 $attachment = wp_get_attachment_image_src( $attachment_id, 'full');347 348 if ( ! is_array( $attachment )) {323 $attachment = wp_get_attachment_image_src($attachment_id, 'full'); 324 325 if (!is_array($attachment)) { 349 326 continue; 350 327 } 351 328 352 $images[] = current( $attachment);329 $images[] = current($attachment); 353 330 } 354 331 355 332 // Set a placeholder image if the product has no images set. 356 if ( empty( $images )) {333 if (empty($images)) { 357 334 358 335 $images[] = wc_placeholder_img_src(); … … 361 338 return $images; 362 339 } 363 364 365 /**366 * Returns thumbnail if it exists, if not, returns the WC placeholder image367 * @param int $id368 * @return string369 */370 private function get_one_thumbnail($id){371 $image = false;372 $thumb_id = get_post_thumbnail_id( $id );373 374 if( $thumb_id )375 $image = wp_get_attachment_image_src( $thumb_id, 'shop_thumbnail' );376 377 if( is_array($image) )378 return $image[0];379 380 return wc_placeholder_img_src();381 }382 340 383 341 … … 410 368 $result = null; 411 369 412 if (isset($array[$name])) 413 { 370 if (isset($array[$name])) { 414 371 $result = $array[$name]; 415 372 } 416 373 417 374 // Handle the default case 418 if (is_null($result)) 419 { 375 if (is_null($result)) { 420 376 $result = $default; 421 377 } 422 378 423 379 // Handle the type constraint 424 switch (strtoupper($type)) 425 { 380 switch (strtoupper($type)) { 426 381 case 'INT': 427 382 case 'INTEGER': … … 444 399 445 400 case 'ARRAY': 446 if (!is_array($result)) 447 { 401 if (!is_array($result)) { 448 402 $result = array($result); 449 403 } … … 466 420 } 467 421 468 469 protected $client_id ; 470 public $url_js ; 422 protected $client_id; 423 protected $additional_html; 471 424 472 425 // Add tracking for pages: 473 public function relevatracking() { 426 public function relevatracking() 427 { 474 428 /** 475 429 * Don't initialize the plugin when WooCommerce is not active. 476 430 */ 477 if ( ! class_exists( 'WooCommerce', false )) {431 if (!class_exists('WooCommerce', false)) { 478 432 return; 479 433 } 480 434 481 435 // is there any option client_id 482 if($this->client_id) { 436 if ($this->client_id) { 437 $additional_html = (string)get_option('relevatracking_additional_html'); 438 if(!$additional_html) { 439 $this->additional_html = '<script type="text/javascript">var relevanzAppForcePixel = true;</script>'; 440 } else { 441 $this->additional_html = $additional_html; 442 } 483 443 // FRONT_PAGE 484 444 $this->retargeting_front_page(); … … 488 448 $this->retargeting_product(); 489 449 // PRODUCT 490 $this->retargeting_cart(); 491 // ORDER SUCCESS PAGE 492 $this->retargeting_confirmation(); 450 $this->retargeting_cart(); 451 493 452 // ANY OTHER PAGE 494 453 $this->retargeting_other(); … … 496 455 } 497 456 498 499 457 // FRONT PAGE Index page 500 public function retargeting_front_page() { 458 public function retargeting_front_page() 459 { 501 460 $user_id = get_current_user_id(); 502 461 503 // URL: https://pix.hyj.mobi/rt?t=d&action=s&cid=CLIENT_ID 504 if ( is_front_page() ) { 505 $this->url_js='https://pix.hyj.mobi/rt?t=d&action=s&cid='.$this->client_id; 506 if($user_id != 0) { 507 $this->url_js .= '&customer_id='.$user_id; 508 } 509 echo $this->render( 'front-page' ); 510 } 511 } 512 513 // CATEGORY PAGE 514 public function retargeting_category() { 462 // URL: https://pix.hyj.mobi/rt?t=d&action=s&cid=CLIENT_ID 463 if (is_front_page()) { 464 $url = 'https://pix.hyj.mobi/rt?t=d&action=s&cid=' . $this->client_id; 465 if ($user_id != 0) { 466 $url .= '&custid=' . $user_id; 467 } 468 $this->addTrackingCode($url); 469 } 470 } 471 472 // CATEGORY PAGE 473 public function retargeting_category() 474 { 515 475 $user_id = get_current_user_id(); 516 476 517 477 // URL: https://pix.hyj.mobi/rt?t=d&action=c&cid=CLIENT_ID&id=CATEGORY_ID 518 //echo "<pre>is_product_taxonomy"; var_export(is_product_taxonomy() ); echo "</pre>";519 if ( function_exists('is_product_category') && is_product_category() ) {520 global $wp_query; 521 // get the query object522 $cat = $wp_query->get_queried_object();523 if(!empty($cat) && is_object($cat)) {524 $id = $cat->term_id;525 $this->url_js='https://pix.hyj.mobi/rt?t=d&action=c&cid='.$this->client_id.'&id='.$id;526 if($user_id != 0) {527 $this->url_js .= '&customer_id='.$user_id;528 }529 echo $this->render( 'front-page' );530 }531 }532 } 533 534 // CATEGORY PAGE 535 public function retargeting_cart(){478 if (function_exists('is_product_category') && is_product_category()) { 479 global $wp_query; 480 // get the query object 481 $cat = $wp_query->get_queried_object(); 482 if (!empty($cat) && is_object($cat)) { 483 $id = $cat->term_id; 484 $url = 'https://pix.hyj.mobi/rt?t=d&action=c&cid=' . $this->client_id . '&id=' . $id; 485 if ($user_id != 0) { 486 $url .= '&custid=' . $user_id; 487 } 488 $this->addTrackingCode($url); 489 } 490 } 491 } 492 493 // CATEGORY PAGE 494 public function retargeting_cart() 495 { 536 496 $user_id = get_current_user_id(); 537 497 538 498 // URL: https://pix.hyj.mobi/rt?t=d&action=w&cid=CLIENT_ID 539 if (is_cart() ) {540 $ this->url_js='https://pix.hyj.mobi/rt?t=d&action=w&cid='.$this->client_id;541 if ($user_id != 0) {542 $ this->url_js .= '&customer_id='.$user_id;543 } 544 echo $this->render( 'front-page' );545 } 546 } 499 if (is_cart()) { 500 $url = 'https://pix.hyj.mobi/rt?t=d&action=w&cid=' . $this->client_id; 501 if ($user_id != 0) { 502 $url .= '&custid=' . $user_id; 503 } 504 $this->addTrackingCode($url); 505 } 506 } 547 507 548 508 // PRODUCT PAGE 549 public function retargeting_product() { 509 public function retargeting_product() 510 { 550 511 $user_id = get_current_user_id(); 551 512 552 //URL: https://pix.hyj.mobi/rt?t=d&action=p&cid=CLIENT_ID&id=PRODUCT_ID553 if ( is_product()) {513 //URL: https://pix.hyj.mobi/rt?t=d&action=p&cid=CLIENT_ID&id=PRODUCT_ID 514 if (is_product()) { 554 515 global $product; 555 $id = $product->get_id();556 if (!$id) {557 $id = get_the_ID();558 } 559 $ this->url_js='https://pix.hyj.mobi/rt?t=d&action=p&cid='.$this->client_id.'&id='.$id;560 if ($user_id != 0) {561 $ this->url_js .= '&customer_id='.$user_id;562 } 563 echo $this->render( 'front-page');516 $id = $product->get_id(); 517 if (!$id) { 518 $id = get_the_ID(); 519 } 520 $url = 'https://pix.hyj.mobi/rt?t=d&action=p&cid=' . $this->client_id . '&id=' . $id; 521 if ($user_id != 0) { 522 $url .= '&custid=' . $user_id; 523 } 524 $this->addTrackingCode($url); 564 525 } 565 526 } … … 567 528 568 529 // Order Success page 569 public function retargeting_confirmation() { 530 public function retargeting_confirmation($order_id) 531 { 570 532 $user_id = get_current_user_id(); 571 /*533 /* 572 534 URL: https://d.hyj.mobi/convNetw?cid=CLIENT_ID&orderId=ORDER_ID&amount=ORDER_TOTAL&eventName=ARTILE_ID1,ARTILE_ID2,ARTILE_ID3&network=relevanz 573 535 */ 574 if ( is_order_received_page() ) { 575 576 $this->load_confirmation_order_id(); 577 $eventname=''; 578 if(count($this->product_ids)) { 536 $this->load_confirmation_order_id(); 537 $eventname = ''; 538 if (count($this->product_ids)) { 579 539 //$eventname = json_encode(implode(',',$this->products_name)); 580 $eventname = implode(',',$this->product_ids); 581 } 582 583 $this->url_js='https://d.hyj.mobi/convNetw?cid='.$this->client_id.'&orderId='.$this->order_id.'&amount='.$this->order_total.'&eventName='.$eventname.'&network=relevanz'; 584 if($user_id != 0) { 585 $this->url_js .= '&customer_id='.$user_id; 586 } 587 588 //echo "<pre>"; var_export($this->url_js); echo "</pre>"; 589 //exit; 590 echo $this->render( 'front-page' ); 591 } 592 } 593 594 public function retargeting_other() { 540 $eventname = implode(',', $this->product_ids); 541 } 542 543 $url = 'https://d.hyj.mobi/convNetw?cid=' . $this->client_id . '&orderId=' . $this->order_id . '&amount=' . $this->order_total . '&eventName=' . $eventname . '&network=relevanz'; 544 if ($user_id != 0) { 545 $url .= '&custid=' . $user_id; 546 } 547 548 $additional_html = (string)get_option('relevatracking_additional_html'); 549 if(!$additional_html) { 550 $this->additional_html = '<script type="text/javascript">var relevanzAppForcePixel = true;</script>'; 551 } else { 552 $this->additional_html = $additional_html; 553 } 554 $this->addTrackingCode($url); 555 } 556 557 558 public function retargeting_other() 559 { 595 560 $user_id = get_current_user_id(); 596 561 597 if (!is_front_page() && !(function_exists('is_product_category') && is_product_category()) && !is_product() && !is_order_received_page() && !is_cart()) {598 $ this->url_js='https://pix.hyj.mobi/rt?t=d&action=s&cid='.$this->client_id;599 if ($user_id != 0) {600 $ this->url_js .= '&customer_id='.$user_id;601 } 602 echo $this->render( 'front-page' );603 } 604 } 605 606 protected $order_id ;562 if (!is_front_page() && !(function_exists('is_product_category') && is_product_category()) && !is_product() && !is_order_received_page() && !is_cart()) { 563 $url = 'https://pix.hyj.mobi/rt?t=d&action=s&cid=' . $this->client_id; 564 if ($user_id != 0) { 565 $url .= '&custid=' . $user_id; 566 } 567 $this->addTrackingCode($url); 568 } 569 } 570 571 protected $order_id; 607 572 protected $products_name = array(); 608 573 protected $product_ids = array(); 609 protected $order_total ;574 protected $order_total; 610 575 611 576 // get Order Success page data 612 private function load_confirmation_order_id() { 613 $key=isset($_GET['key'])?$_GET['key']:null; 614 $this->order_id = wc_get_order_id_by_order_key( $key ); 615 //wc_order_59576109b13fa 616 if($this->order_id) { 617 $order = new \WC_Order( $this->order_id ); 618 $this->order_id = $order->get_order_number(); 619 $this->order_total = number_format( (float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping(), wc_get_price_decimals(), '.', '' ); 620 foreach ( $order->get_items() as $item ) { 621 622 if ( $item['variation_id'] ) { 623 $product = new \WC_Product_Variation( $item['variation_id'] ); 624 $id = $product->get_parent_id(); 625 } else { 626 $product = new \WC_Product( $item['product_id'] ); 627 $id = $product->get_id(); 628 } 629 $this->products_name[] = $product->get_name(); 630 $this->product_ids[] = $id; 631 } 632 return true; 577 private function load_confirmation_order_id() 578 { 579 $key = isset($_GET['key']) ? $_GET['key'] : null; 580 $this->order_id = wc_get_order_id_by_order_key($key); 581 582 if ($this->order_id) { 583 $order = new \WC_Order($this->order_id); 584 $this->order_id = $order->get_order_number(); 585 $this->order_total = number_format((float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping(), wc_get_price_decimals(), '.', ''); 586 foreach ($order->get_items() as $item) { 587 588 if ($item['variation_id']) { 589 $product = new \WC_Product_Variation($item['variation_id']); 590 $id = $product->get_parent_id(); 591 } else { 592 $product = new \WC_Product($item['product_id']); 593 $id = $product->get_id(); 594 } 595 $this->products_name[] = $product->get_name(); 596 $this->product_ids[] = $id; 597 } 598 return true; 633 599 } 634 600 return false; 635 601 } 636 602 637 private function escapeJavaScriptText($string) 638 { 639 return str_replace("\n", '\n', str_replace('"', '\"', addcslashes(str_replace("\r", '', (string)$string), "\0..\37'\\"))); 640 } 641 642 643 public function load_current_category_id() { 603 604 public function load_current_category_id() 605 { 644 606 645 607 global $wp_query; … … 648 610 } 649 611 650 public function load_category_products_id() { 612 public function load_category_products_id() 613 { 651 614 652 615 global $wp_query; 653 616 $this->products_id = array(); 654 foreach ( $wp_query->posts as $product_post) {655 $product = new \WC_Product( $product_post->ID);617 foreach ($wp_query->posts as $product_post) { 618 $product = new \WC_Product($product_post->ID); 656 619 $this->products_id[] = $product->get_sku(); 657 620 } 658 621 } 659 622 660 public function load_product_categories_id() { 623 public function load_product_categories_id() 624 { 661 625 662 626 global $post; 663 $product_categories = get_the_terms( $post->ID, 'product_cat' ); 664 $this->product_categories_id = array_keys( $product_categories ); 665 } 666 667 public function load_product_id() { 627 $product_categories = get_the_terms($post->ID, 'product_cat'); 628 $this->product_categories_id = array_keys($product_categories); 629 } 630 631 public function load_product_id() 632 { 668 633 669 634 global $post; 670 $product = new \WC_Product( $post->ID);635 $product = new \WC_Product($post->ID); 671 636 $this->product_id = $product->get_sku(); 672 637 } 673 638 674 public function load_product_price() { 639 public function load_product_price() 640 { 675 641 676 642 global $product; … … 678 644 } 679 645 680 public function load_cart_products_id() { 646 public function load_cart_products_id() 647 { 681 648 682 649 $this->products_id = array(); 683 foreach ( WC()->cart->get_cart() as $cart_item) {650 foreach (WC()->cart->get_cart() as $cart_item) { 684 651 $this->products_id[] = $cart_item['data']->get_sku(); 685 652 } 686 653 } 687 654 688 public function load_cart_products_price() { 655 public function load_cart_products_price() 656 { 689 657 690 658 $this->cart_products_price = array(); 691 foreach ( WC()->cart->get_cart() as $cart_item) {659 foreach (WC()->cart->get_cart() as $cart_item) { 692 660 $this->cart_products_price[] = $cart_item['data']->get_price(); 693 661 } 694 662 } 695 663 696 public function load_cart_total() { 664 public function load_cart_total() 665 { 697 666 698 667 $this->cart_total = WC()->cart->cart_contents_total; … … 700 669 701 670 702 public function load_confirmation_products_price() { 703 704 $order_id = wc_get_order_id_by_order_key( $_GET['key'] ); 705 $order = new \WC_Order( $order_id ); 671 public function load_confirmation_products_price() 672 { 673 674 $order_id = wc_get_order_id_by_order_key($_GET['key']); 675 $order = new \WC_Order($order_id); 706 676 707 677 $this->products_price = array(); 708 foreach ( $order->get_items() as $item) {709 710 if ( $item['variation_id']) {711 $product = new \WC_Product_Variation( $item['variation_id']);678 foreach ($order->get_items() as $item) { 679 680 if ($item['variation_id']) { 681 $product = new \WC_Product_Variation($item['variation_id']); 712 682 } else { 713 $product = new \WC_Product( $item['product_id']);683 $product = new \WC_Product($item['product_id']); 714 684 } 715 685 $this->products_price[] = $product->get_price(); … … 717 687 } 718 688 719 public function load_currency() { 689 public function load_currency() 690 { 720 691 721 692 $this->currency = 'EUR'; 722 693 } 723 694 724 public function load_new_customer() { 695 public function load_new_customer() 696 { 725 697 726 698 global $current_user; 727 699 728 700 $this->new_customer = 0; 729 if ( isset( $current_user->ID )) {701 if (isset($current_user->ID)) { 730 702 $args = array(); 731 703 $args['post_type'] = 'shop_order'; … … 734 706 $args['meta_key'] = '_customer_user'; 735 707 $args['meta_value'] = $current_user->ID; 736 $wp_query = new \WP_Query( $args);737 $orders_id = wp_list_pluck( $wp_query->posts, 'ID');708 $wp_query = new \WP_Query($args); 709 $orders_id = wp_list_pluck($wp_query->posts, 'ID'); 738 710 wp_reset_query(); 739 711 // First order 740 if ( count( $orders_id ) == 1) {712 if (count($orders_id) == 1) { 741 713 $this->new_customer = 1; 742 714 }; … … 744 716 } 745 717 746 public function render( $view_file ) { 747 748 ob_start(); 749 include plugin_dir_path( __FILE__ ) . 'partials/' . $view_file . '.php'; 750 $result = ob_get_contents(); 751 ob_end_clean(); 752 return $result; 753 } 754 755 /** 756 * Register the stylesheets for the public-facing side of the site. 757 * 758 * @since 1.0.0 759 */ 760 public function enqueue_styles() { 761 762 /** 763 * This function is provided for demonstration purposes only. 764 * 765 * An instance of this class should be passed to the run() function 766 * defined in Relevatracking_Loader as all of the hooks are defined 767 * in that particular class. 768 * 769 * The Relevatracking_Loader will then create the relationship 770 * between the defined hooks and the functions defined in this 771 * class. 772 */ 773 774 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/relevatracking-public.css', array(), $this->version, 'all' ); 775 776 } 777 778 /** 779 * Register the JavaScript for the public-facing side of the site. 780 * 781 * @since 1.0.0 782 */ 783 public function enqueue_scripts() { 784 785 /** 786 * This function is provided for demonstration purposes only. 787 * 788 * An instance of this class should be passed to the run() function 789 * defined in Relevatracking_Loader as all of the hooks are defined 790 * in that particular class. 791 * 792 * The Relevatracking_Loader will then create the relationship 793 * between the defined hooks and the functions defined in this 794 * class. 795 */ 796 797 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/relevatracking-public.js', array( 'jquery' ), $this->version, false ); 798 799 } 800 718 public function addTrackingCode($url) { 719 // add base code 720 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/relevatracking-public.js', array(), $this->version, false); 721 // add url 722 wp_add_inline_script($this->plugin_name, 'var relevanzURL = "' . $url . '";', 'before'); 723 // add additional html 724 wp_add_inline_script($this->plugin_name, $this->additional_html, 'before'); 725 } 801 726 } -
releva-nz/trunk/public/js/relevatracking-public.js
r1812925 r2988403 1 (function( $ ) { 2 'use strict'; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 32 })( jQuery ); 1 var relevanzRetargetingForcePixelInterval = window.setInterval(function () { 2 if (typeof relevanzAppForcePixel !== "undefined" && relevanzAppForcePixel === true) { 3 window.clearInterval(relevanzRetargetingForcePixelInterval); 4 var script = document.createElement('script'); 5 script.type = 'text/javascript'; 6 script.src = relevanzURL; 7 document.body.appendChild(script); 8 } 9 }, 500); -
releva-nz/trunk/relevatracking.php
r2747436 r2988403 17 17 * Plugin URI: https://releva.nz 18 18 * Description: Technology for personalized advertising 19 * Version: 2.1. 319 * Version: 2.1.5 20 20 * Author: releva.nz 21 21 * License: GPL-2.0+
Note: See TracChangeset
for help on using the changeset viewer.