PluginProbe
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools / 1.0.8
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools v1.0.8
1.5.5 1.5.4 trunk 1.0.0 1.0.1 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 All 47 releases
pixelavo / includes / add-pixel.php

add-pixel.php in Pixelavo – Server Side Tracking & Pixel + AI Ads Tools 1.0.8, at includes/add-pixel.php

95 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Pixelavo;
4
5 /**
6 * Exit if accessed directly
7 * */
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 class AddPixel{
13
14 private static $_instance = null;
15
16 /**
17 * Instance
18 *
19 * Initializes a singleton instance
20 *
21 * @return self self class
22 */
23 static function instance() {
24 if ( is_null( self::$_instance ) ) {
25 self::$_instance = new self();
26 }
27 return self::$_instance;
28 }
29
30 private function __construct() {
31 add_action('wp_head', [ $this, 'add_pixels']);
32 }
33
34 /**
35 * Add pixel to the site.
36 *
37 * @return void
38 */
39 function add_pixels() {
40 $pixels = pixelavo_get_pixel_list(apply_filters('pixelavo_pixels_limit', 1));
41
42 $pixelInitCode = '';
43 $pixelNoScriptCode = '';
44 $advanced_matching = apply_filters('pixelavo_advanced_matching', []);
45 $advanced_matching_hashed = apply_filters('pixelavo_advanced_matching_hashed', []);
46
47 if(!empty($pixels)) {
48
49 /**
50 * Loop for pixel init & noscript code.
51 */
52 foreach ($pixels as $pixel) {
53 if($pixel['active'] == 'on' && pixelavo_check_pixel_page($pixel)) {
54 if(!empty($advanced_matching)) {
55 $pixelInitCode .= "fbq('init', {$pixel['pixel_id']}, $advanced_matching);" . "\n";
56 $pixelNoScriptCode .= "<img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id={$pixel['pixel_id']}&ev=PageView&noscript=1&ud[em]={$advanced_matching_hashed['em']}&ud[fn]={$advanced_matching_hashed['fn']}&ud[ln]={$advanced_matching_hashed['ln']}&ud[ph]={$advanced_matching_hashed['ph']}&ud[ct]={$advanced_matching_hashed['ct']}&ud[st]={$advanced_matching_hashed['st']}&ud[zp]={$advanced_matching_hashed['zp']}&ud[country]={$advanced_matching_hashed['country']}'/>" . "\n";
57 } else {
58 $pixelInitCode .= "fbq('init', {$pixel['pixel_id']});" . "\n";
59 $pixelNoScriptCode .= "<img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id={$pixel['pixel_id']}&ev=PageView&noscript=1'/>" . "\n";
60 }
61 }
62 }
63
64 /**
65 * Print facebook pixel code to the browser.
66 */
67 if(pixelavo_pixel_status() && !pixelavo_check_exclude_roles()) {
68 ob_start();
69 echo "<script>
70 !function(f,b,e,v,n,t,s)
71 {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
72 n.callMethod.apply(n,arguments):n.queue.push(arguments)};
73 if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
74 n.queue=[];t=b.createElement(e);t.async=!0;
75 t.src=v;s=b.getElementsByTagName(e)[0];
76 s.parentNode.insertBefore(t,s)}(window, document,'script',
77 'https://connect.facebook.net/en_US/fbevents.js');
78 {$pixelInitCode}
79 fbq('track', 'PageView');
80 </script>
81 <noscript>
82 {$pixelNoScriptCode}
83 </noscript>";
84 echo ob_get_clean();
85 }
86
87 }
88 }
89 }
90
91 /**
92 * Initialize AddPixel Class
93 */
94 AddPixel::instance();
95