includes();
//Load Tracking Analytics
add_action( 'wp_head', array( $this, 'hook_analytics_4' ) );
//Load Tracking Analytics Remarketing
add_action( 'wp_footer', array( $this, 'hook_analytics_remarketing' ) );
//Load Tracking Facebook ID
add_action( 'wp_head', array( $this, 'hook_facebook_pixel_code' ) );
//Load Tracking Google Tag Manager in Head and after Body
add_action('wp_head', array($this, 'hook_google_tag_manager_head'));
add_filter('template_include', array( $this, 'custom_include' ),0 );
add_filter('wp_body_open', array( $this, 'hook_google_tag_manager_body' ),0);
add_action( 'before_woocommerce_init', array( $this, 'declare_compatibility_hpos') );
}
/**
* Return an instance of this class.
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Get templates path.
*
* @return string
*/
public static function get_templates_path() {
return plugin_dir_path( __FILE__ ) . 'templates/';
}
/**
* Load the plugin text domain for translation.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wp-tracking-codes', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Instalation Plugin
*/
public function wp_tracking_codes_install() {
// Trigger our function that registers the custom post type
pluginprefix_setup_post_types();
// Clear the permalinks after the post type has been registered
flush_rewrite_rules();
}
/**
* Includes
*/
private function includes() {
include_once 'includes/class-register-codes.php';
include_once 'includes/class-render-data-layer-gtm.php';
include_once 'includes/class-render-google-merchant.php';
}
/**
* Debug
*/
public function log_me($message) {
if (WP_DEBUG === true) {
if (is_array($message) || is_object($message)) {
error_log(print_r($message, true));
} else {
error_log($message);
}
}
}
public function hook_analytics_4(){
$this->options = get_option( 'tracking_option' );
if( isset( $this->options['analytics_4'] ) && !empty( $this->options['analytics_4'] ) ){
$analytics_4 = $this->options['analytics_4'];
printf("
", esc_attr($analytics_4), esc_attr($analytics_4));
}
}
public function hook_analytics_remarketing() {
$this->options = get_option( 'tracking_option' );
if( isset( $this->options['analytics_remarketing'] ) && !empty( $this->options['analytics_remarketing'] ) ){
$analytics_remarketing = $this->options['analytics_remarketing'];
printf("
", esc_attr($analytics_remarketing), esc_attr($analytics_remarketing));
}
}
public function hook_facebook_pixel_code() {
$this->options = get_option( 'tracking_option' );
if ( isset( $this->options['facebook_pixel_code'] ) && ! empty( $this->options['facebook_pixel_code'] ) ){
$facebook_pixel_code = $this->options['facebook_pixel_code'];
printf( "
", esc_attr($facebook_pixel_code) );
}
}
public function custom_include($template) {
ob_start();
return $template;
}
public function hook_google_tag_manager_head(){
$this->options = get_option('tracking_option');
if ( isset( $this->options['google_tag_manager'] ) && !empty($this->options['google_tag_manager'])){
$google_tag_manager = $this->options['google_tag_manager'];
printf(
"
",
esc_attr( $google_tag_manager )
);
}
}
public function hook_google_tag_manager_body($classes){
$this->options = get_option( 'tracking_option' );
if( isset( $this->options['google_tag_manager'] ) && !empty( $this->options['google_tag_manager'] ) ){
$google_tag_manager = $this->options['google_tag_manager'];
printf("
",
esc_attr( $google_tag_manager )
);
}
}
/**
* Declare_compatibility_hpos
*/
public function declare_compatibility_hpos() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', 'wp-tracking-codes/wp-tracking-codes.php', true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', 'wp-tracking-codes/wp-tracking-codes.php', true );
}
}
}
add_action( 'plugins_loaded', array( 'Wp_Tracking_Codes', 'get_instance' ) );
endif;