<?php
       class UniPixel_AddToCart_Fragment_Collector { private static $platform_data = []; private static $server_results = []; public static function add_platform_data($platform_key, array $client_data) { self::$platform_data[$platform_key] = $client_data; } public static function add_server_result($platform_key, $event_name, array $result_info) { self::$server_results[$platform_key] = [ 'event_name' => $event_name, 'payload' => $result_info["\x70\x61\x79\x6C\x6F\x61\x64"] ?? [], 'response' => $result_info["\x72\x65\x73\x70\x6F\x6E\x73\x65"] ?? [], ]; } public static function get_platform_data() { return self::$platform_data; } public static function get_server_results() { return self::$server_results; } public static function has_data() { return !empty(self::$platform_data); } }     add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x66\x72\x61\x67\x6D\x65\x6E\x74\x5F\x70\x6C\x61\x63\x65\x68\x6F\x6C\x64\x65\x72"); function unipixel_addtocart_fragment_placeholder() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } echo '<div class="unipixel-addtocart-fragment" style="display:none;"></div>'; }     add_filter('woocommerce_add_to_cart_fragments', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x66\x72\x61\x67\x6D\x65\x6E\x74\x73", 10, 1); function unipixel_addtocart_fragments($fragments) { if (! UniPixel_AddToCart_Fragment_Collector::has_data()) { return $fragments; } $platform_data = UniPixel_AddToCart_Fragment_Collector::get_platform_data(); $server_results = UniPixel_AddToCart_Fragment_Collector::get_server_results(); $js_parts = [];  if (isset($platform_data["\x6D\x65\x74\x61"])) { $json = wp_json_encode($platform_data["\x6D\x65\x74\x61"]); $js_parts[] = "(function(){
			var d = {$json};
			if (typeof fbq !== 'undefined') {
				var payload = {
					contents: [{ id: d.product_id, quantity: d.quantity, price: d.price }],
					currency: d.currency,
					value: d.price * d.quantity,
					content_type: d.content_type,
					content_ids: d.content_ids
				};
				if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
					UniPixelConsoleLogger.log('SEND', 'Meta | Client-side event sent | AddToCart object:', d);
				}
				fbq('track', 'AddToCart', payload, { eventID: d.event_id });
			}
		})();"; } if (isset($platform_data["\x67\x6F\x6F\x67\x6C\x65"])) { $json = wp_json_encode($platform_data["\x67\x6F\x6F\x67\x6C\x65"]); $js_parts[] = "(function(){
			var d = {$json};
			var payload = {
				event_id: d.event_id,
				items: [{ item_id: d.product_id, item_name: d.item_name, quantity: d.quantity, price: d.price }],
				currency: d.currency,
				value: d.price * d.quantity,
				event_send_method: 'clientSecond'
			};
			if (d.item_variant) { payload.items[0].item_variant = d.item_variant; }
			if (d.gclid) { payload.gclid = d.gclid; }
			if (d.debug_mode) { payload.debug_mode = true; }
			if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
				UniPixelConsoleLogger.log('SEND', 'Google | Client-side event sent | add_to_cart object:', d);
			}
			if (typeof gtag !== 'undefined') {
				gtag('event', 'add_to_cart', payload);
			} else if (typeof window.dataLayer !== 'undefined' && Array.isArray(window.dataLayer)) {
				window.dataLayer.push(Object.assign({ event: 'add_to_cart' }, payload));
			}
		})();"; } if (isset($platform_data["\x74\x69\x6B\x74\x6F\x6B"])) { $json = wp_json_encode($platform_data["\x74\x69\x6B\x74\x6F\x6B"]); $js_parts[] = "(function(){
			var d = {$json};
			if (typeof ttq !== 'undefined') {
				var payload = {
					contents: [{ content_id: d.product_id, content_name: d.item_name, content_type: 'product', quantity: d.quantity, price: d.price }],
					currency: d.currency,
					value: d.price * d.quantity
				};
				if (d.ttclid) { payload.ttclid = d.ttclid; }
				if (d.ttp) { payload.ttp = d.ttp; }
				if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
					UniPixelConsoleLogger.log('SEND', 'TikTok | Client-side event sent | AddToCart object:', d);
				}
				ttq.track('AddToCart', payload, { event_id: d.event_id });
			}
		})();"; } if (isset($platform_data["\x70\x69\x6E\x74\x65\x72\x65\x73\x74"])) { $json = wp_json_encode($platform_data["\x70\x69\x6E\x74\x65\x72\x65\x73\x74"]); $js_parts[] = "(function(){
			var d = {$json};
			if (typeof pintrk === 'function') {
				var payload = {
					value: d.value,
					currency: d.currency,
					content_ids: d.content_ids,
					num_items: 1
				};
				if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
					UniPixelConsoleLogger.log('SEND', 'Pinterest | Client-side event sent | AddToCart object:', d);
				}
				pintrk('track', 'addtocart', payload, { event_id: d.event_id });
			}
		})();"; } if (isset($platform_data["\x6D\x69\x63\x72\x6F\x73\x6F\x66\x74"])) { $json = wp_json_encode($platform_data["\x6D\x69\x63\x72\x6F\x73\x6F\x66\x74"]); $js_parts[] = "(function(){
			var d = {$json};
			window.uetq = window.uetq || [];
			var payload = {
				event_id: d.event_id,
				ecomm_pagetype: 'cart',
				currency: d.currency,
				ecomm_totalvalue: d.price * d.quantity,
				items: [{ id: d.product_id, name: d.item_name, quantity: d.quantity, price: d.price }]
			};
			if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
				UniPixelConsoleLogger.log('SEND', 'Microsoft | Client-side event sent | AddToCart object:', d);
			}
			window.uetq.push('event', 'add_to_cart', payload);
		})();"; }  $platform_labels = [ 'meta' => "\x4D\x65\x74\x61", 'google' => "\x47\x6F\x6F\x67\x6C\x65", 'tiktok' => "\x54\x69\x6B\x54\x6F\x6B", 'pinterest' => "\x50\x69\x6E\x74\x65\x72\x65\x73\x74", 'microsoft' => "\x4D\x69\x63\x72\x6F\x73\x6F\x66\x74", ]; foreach ($server_results as $key => $sr) { $label = $platform_labels[$key] ?? $key; $sr_json = wp_json_encode($sr); $js_parts[] = "(function(){
			if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
				var sr = {$sr_json};
				UniPixelConsoleLogger.log('SEND', '{$label} | Server-side event sent | ' + sr.event_name + ' object:', sr.payload);
				if (sr.response && Object.keys(sr.response).length > 0) {
					UniPixelConsoleLogger.log('RESPONSE', '{$label} | Platform response | ' + sr.event_name + ' object:', sr.response);
				}
			}
		})();"; }  if (!empty($js_parts)) { $combined_js = implode("\n", $js_parts); $fragments["\x64\x69\x76\x2E\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x2D\x66\x72\x61\x67\x6D\x65\x6E\x74"] = '<div class="unipixel-addtocart-fragment" style="display:none;">' . "\x3C\x73\x63\x72\x69\x70\x74\x3E" . $combined_js . '</script>' . '</div>'; } return $fragments; }       function unipixel_inline_script_meta_addtocart($triggerHook = "", $genericData = null) { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(1, "\x41\x64\x64\x54\x6F\x43\x61\x72\x74")) { return; } $script = "
        if (typeof UniPixelAddToCartMeta !== 'undefined' && typeof fbq !== 'undefined') {
            var payload = {
                contents: [{
                    id: UniPixelAddToCartMeta.product_id,
                    quantity: UniPixelAddToCartMeta.quantity,
                    price: UniPixelAddToCartMeta.price
                }],
                currency: UniPixelAddToCartMeta.currency,
                value: UniPixelAddToCartMeta.price * UniPixelAddToCartMeta.quantity,
                content_type: UniPixelAddToCartMeta.content_type,
                content_ids: UniPixelAddToCartMeta.content_ids
            };

            if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
                UniPixelConsoleLogger.log('SEND', 'Meta | Client-side event sent | AddToCart object:', UniPixelAddToCartMeta);
                // UniPixelConsoleLogger.log('SEND', 'Meta | Client-side event sent | AddToCart data sent:', payload);
            }

            fbq('track', 'AddToCart', payload, { eventID: UniPixelAddToCartMeta.event_id });
        } else {
            if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
                UniPixelConsoleLogger.error('Meta | AddToCart payload not sent: UniPixelAddToCartMeta or fbq is undefined');
            }
        }
        "; if ($triggerHook === 'woocommerce_add_to_cart') { $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_meta_' . $user_identifier; set_transient($transient_key, array( 'genericData' => $genericData, 'script' => $script ), HOUR_IN_SECONDS); } else { wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $script, "\x61\x66\x74\x65\x72"); } } function unipixel_handle_session_addtocart_meta() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(1, "\x41\x64\x64\x54\x6F\x43\x61\x72\x74")) { return; } $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_meta_' . $user_identifier;  if (false !== ($data = get_transient($transient_key))) { $script = isset($data["\x73\x63\x72\x69\x70\x74"]) ? $data["\x73\x63\x72\x69\x70\x74"] : ""; $genericData = isset($data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"]) ? $data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"] : null; $eventTimeStampMs = (int) round(microtime(true) * 1000); if (!empty($genericData)) {  unipixel_localize_add_to_cart_for_meta($genericData, $eventTimeStampMs); } $wrappedScript = "jQuery(document).ready(function() { " . $script . "\x20\x7D\x29\x3B"; wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $wrappedScript, "\x61\x66\x74\x65\x72");  delete_transient($transient_key); } } add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x68\x61\x6E\x64\x6C\x65\x5F\x73\x65\x73\x73\x69\x6F\x6E\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x6D\x65\x74\x61");  function unipixel_inline_script_google_addtocart($triggerHook = "", $genericData = null) { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(4, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $opts = get_option('unipixel_logging_options', []); $enableGoogleDebugViewClientSide = ! empty($opts["\x65\x6E\x61\x62\x6C\x65\x47\x6F\x6F\x67\x6C\x65\x44\x65\x62\x75\x67\x56\x69\x65\x77\x43\x6C\x69\x65\x6E\x74\x53\x69\x64\x65"]); $googleDebugViewJs = $enableGoogleDebugViewClientSide ? "\x70\x61\x79\x6C\x6F\x61\x64\x2E\x64\x65\x62\x75\x67\x5F\x6D\x6F\x64\x65\x20\x3D\x20\x74\x72\x75\x65\x3B" : ""; $script = "
    if (typeof UniPixelAddToCartGoogle !== 'undefined') {
        var payload = {
            event_id: UniPixelAddToCartGoogle.event_id,
            items: [{
                item_id: UniPixelAddToCartGoogle.product_id,
                item_name: UniPixelAddToCartGoogle.item_name,
                quantity: UniPixelAddToCartGoogle.quantity,
                price: UniPixelAddToCartGoogle.price
            }],
            currency: UniPixelAddToCartGoogle.currency,
            value: UniPixelAddToCartGoogle.price * UniPixelAddToCartGoogle.quantity,
            event_send_method: 'clientSecond'
        };

        if (UniPixelAddToCartGoogle.item_variant) {
            payload.items[0].item_variant = UniPixelAddToCartGoogle.item_variant;
        }

        if (UniPixelAddToCartGoogle.gclid) {
            payload.gclid = UniPixelAddToCartGoogle.gclid;
        }

        {$googleDebugViewJs}

        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.log('SEND', 'Google | Client-side event sent | add_to_cart object:', UniPixelAddToCartGoogle);
            // UniPixelConsoleLogger.log('SEND', 'Google | Client-side event sent | add_to_cart data sent:', payload);
        }

        if (typeof gtag !== 'undefined') {
            if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
                UniPixelConsoleLogger.log('SEND', 'Google AddToCart: using gtag() branch');
            }
            gtag('event', 'add_to_cart', payload);
        } else if (typeof window.dataLayer !== 'undefined' && Array.isArray(window.dataLayer)) {
            if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
                UniPixelConsoleLogger.log('SEND', 'Google AddToCart: using dataLayer.push branch');
            }
            window.dataLayer.push(
                Object.assign({ event: 'add_to_cart' }, payload)
            );
        } else {
            if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
                UniPixelConsoleLogger.error('Google AddToCart: no tracking method detected');
            }
        }
    } else {
        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.error('Google | add_to_cart payload not sent: UniPixelAddToCartGoogle is undefined');
        }
    }
    "; if ($triggerHook === 'woocommerce_add_to_cart') { $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_google_' . $user_identifier; set_transient($transient_key, array( 'genericData' => $genericData, 'script' => $script ), HOUR_IN_SECONDS); } else { wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $script, "\x61\x66\x74\x65\x72"); } } function unipixel_handle_session_addtocart_google() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(4, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_google_' . $user_identifier; $data = get_transient($transient_key); if ($data !== false) { $script = isset($data["\x73\x63\x72\x69\x70\x74"]) ? $data["\x73\x63\x72\x69\x70\x74"] : ""; $genericData = isset($data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"]) ? $data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"] : null;  if (!empty($genericData)) { unipixel_localize_add_to_cart_for_google($genericData); }  $wrappedScript = "jQuery(document).ready(function() { " . $script . "\x20\x7D\x29\x3B"; wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $wrappedScript, "\x61\x66\x74\x65\x72");  delete_transient($transient_key); } } add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x68\x61\x6E\x64\x6C\x65\x5F\x73\x65\x73\x73\x69\x6F\x6E\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x67\x6F\x6F\x67\x6C\x65");  function unipixel_inline_script_tiktok_addtocart($triggerHook = "", $genericData = null) { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; }  if (! unipixel_is_woo_event_enabled(3, "\x41\x64\x64\x54\x6F\x43\x61\x72\x74")) { return; } $script = "
    if (typeof UniPixelAddToCartTikTok !== 'undefined' && typeof ttq !== 'undefined') {
        var payload = {
            contents: [{
                content_id:   UniPixelAddToCartTikTok.product_id,
                content_name: UniPixelAddToCartTikTok.item_name,
                content_type: 'product',
                quantity:     UniPixelAddToCartTikTok.quantity,
                price:        UniPixelAddToCartTikTok.price
            }],
            currency: UniPixelAddToCartTikTok.currency,
            value:    UniPixelAddToCartTikTok.price * UniPixelAddToCartTikTok.quantity
        };

        if (UniPixelAddToCartTikTok.ttclid) {
            payload.ttclid = UniPixelAddToCartTikTok.ttclid;
        }
        if (UniPixelAddToCartTikTok.ttp) {
            payload.ttp = UniPixelAddToCartTikTok.ttp;
        }

        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.log('SEND', 'TikTok | Client-side event sent | AddToCart object:', UniPixelAddToCartTikTok);
        }

        ttq.track('AddToCart', payload, { event_id: UniPixelAddToCartTikTok.event_id });
    } else {
        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.error('TikTok | AddToCart payload not sent: UniPixelAddToCartTikTok or ttq is undefined');
        }
    }
";  if ($triggerHook === 'woocommerce_add_to_cart') { $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_tiktok_' . $user_identifier; set_transient($transient_key, array( 'genericData' => $genericData, 'script' => $script ), HOUR_IN_SECONDS); } else { wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $script, "\x61\x66\x74\x65\x72"); } } function unipixel_handle_session_addtocart_tiktok() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(3, "\x41\x64\x64\x54\x6F\x43\x61\x72\x74")) { return; } $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_tiktok_' . $user_identifier;  if (false !== ($data = get_transient($transient_key))) { $script = isset($data["\x73\x63\x72\x69\x70\x74"]) ? $data["\x73\x63\x72\x69\x70\x74"] : ""; $genericData = isset($data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"]) ? $data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"] : null; if (!empty($genericData)) {  unipixel_localize_add_to_cart_for_tiktok($genericData); } $wrappedScript = "jQuery(document).ready(function() { " . $script . "\x20\x7D\x29\x3B"; wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $wrappedScript, "\x61\x66\x74\x65\x72");  delete_transient($transient_key); } } add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x68\x61\x6E\x64\x6C\x65\x5F\x73\x65\x73\x73\x69\x6F\x6E\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x74\x69\x6B\x74\x6F\x6B");  add_action('wp_footer', function () { $uid = unipixel_get_user_identifier_for_transient();  $k = 'unipixel_addtocart_server_meta_' . $uid; if (false !== ($data = get_transient($k))) { unipixel_localize_console_logging_for_meta("\x41\x64\x64\x54\x6F\x43\x61\x72\x74", $data); delete_transient($k); }  $k = 'unipixel_addtocart_server_google_' . $uid; if (false !== ($data = get_transient($k))) { unipixel_localize_console_logging_for_google("\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74", $data); delete_transient($k); }  $k = 'unipixel_addtocart_server_tiktok_' . $uid; if (false !== ($data = get_transient($k))) { unipixel_localize_console_logging_for_tiktok("\x41\x64\x64\x54\x6F\x43\x61\x72\x74", $data); delete_transient($k); }  $k = 'unipixel_addtocart_server_pinterest_' . $uid; if (false !== ($data = get_transient($k))) { unipixel_localize_console_logging_for_pinterest("\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74", $data); delete_transient($k); }  $k = 'unipixel_addtocart_server_microsoft_' . $uid; if (false !== ($data = get_transient($k))) { unipixel_localize_console_logging_for_microsoft("\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74", $data); delete_transient($k); } });  function unipixel_inline_script_pinterest_addtocart($triggerHook = "", $genericData = null) { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(2, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $script = "
    if (typeof UniPixelAddToCartPinterest !== 'undefined' && typeof pintrk === 'function') {
        var payload = {
            value:       UniPixelAddToCartPinterest.value,
            currency:    UniPixelAddToCartPinterest.currency,
            content_ids: UniPixelAddToCartPinterest.content_ids,
            num_items:   1
        };

        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.log('SEND', 'Pinterest | Client-side event sent | AddToCart object:', UniPixelAddToCartPinterest);
        }

        pintrk('track', 'addtocart', payload, { event_id: UniPixelAddToCartPinterest.event_id });
    } else {
        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.error('Pinterest | AddToCart payload not sent: UniPixelAddToCartPinterest or pintrk is undefined');
        }
    }
"; if ($triggerHook === 'woocommerce_add_to_cart') { $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_pinterest_' . $user_identifier; set_transient($transient_key, array( 'genericData' => $genericData, 'script' => $script ), HOUR_IN_SECONDS); } else { wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $script, "\x61\x66\x74\x65\x72"); } } function unipixel_handle_session_addtocart_pinterest() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(2, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_pinterest_' . $user_identifier; if (false !== ($data = get_transient($transient_key))) { $script = isset($data["\x73\x63\x72\x69\x70\x74"]) ? $data["\x73\x63\x72\x69\x70\x74"] : ""; $genericData = isset($data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"]) ? $data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"] : null; if (!empty($genericData)) { unipixel_localize_add_to_cart_for_pinterest($genericData); } $wrappedScript = "jQuery(document).ready(function() { " . $script . "\x20\x7D\x29\x3B"; wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $wrappedScript, "\x61\x66\x74\x65\x72"); delete_transient($transient_key); } } add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x68\x61\x6E\x64\x6C\x65\x5F\x73\x65\x73\x73\x69\x6F\x6E\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x70\x69\x6E\x74\x65\x72\x65\x73\x74");  function unipixel_inline_script_microsoft_addtocart($triggerHook = '', $genericData = null) { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; }  if (! unipixel_is_woo_event_enabled(5, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $script = "
    if (typeof UniPixelAddToCartMicrosoft !== 'undefined') {
        window.uetq = window.uetq || [];

        var payload = {
            event_id:       UniPixelAddToCartMicrosoft.event_id,
            ecomm_pagetype: 'cart',
            currency:       UniPixelAddToCartMicrosoft.currency,
            ecomm_totalvalue: UniPixelAddToCartMicrosoft.price * UniPixelAddToCartMicrosoft.quantity,
            items: [{
                id:       UniPixelAddToCartMicrosoft.product_id,
                name:     UniPixelAddToCartMicrosoft.item_name,
                quantity: UniPixelAddToCartMicrosoft.quantity,
                price:    UniPixelAddToCartMicrosoft.price
            }]
        };

        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.log('SEND', 'Microsoft | Client-side event sent | AddToCart object:', UniPixelAddToCartMicrosoft);
        }

        window.uetq.push('event', 'add_to_cart', payload);
    } else {
        if (window.__UniPixelConsoleActive && typeof UniPixelConsoleLogger !== 'undefined') {
            UniPixelConsoleLogger.error('Microsoft | AddToCart payload not sent: UniPixelAddToCartMicrosoft is undefined');
        }
    }
"; if ($triggerHook === 'woocommerce_add_to_cart') { $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_microsoft_' . $user_identifier; set_transient($transient_key, array( 'genericData' => $genericData, 'script' => $script ), HOUR_IN_SECONDS); } else { wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $script, "\x61\x66\x74\x65\x72"); } } function unipixel_handle_session_addtocart_microsoft() { if (! class_exists("\x57\x6F\x6F\x43\x6F\x6D\x6D\x65\x72\x63\x65")) { return; } if (! unipixel_is_woo_event_enabled(5, "\x61\x64\x64\x5F\x74\x6F\x5F\x63\x61\x72\x74")) { return; } $user_identifier = unipixel_get_user_identifier_for_transient(); $transient_key = 'unipixel_addtocart_event_microsoft_' . $user_identifier; if (false !== ($data = get_transient($transient_key))) { $script = isset($data["\x73\x63\x72\x69\x70\x74"]) ? $data["\x73\x63\x72\x69\x70\x74"] : ""; $genericData = isset($data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"]) ? $data["\x67\x65\x6E\x65\x72\x69\x63\x44\x61\x74\x61"] : null; if (!empty($genericData)) { unipixel_localize_add_to_cart_for_microsoft($genericData); } $wrappedScript = "jQuery(document).ready(function() { " . $script . "\x20\x7D\x29\x3B"; wp_add_inline_script("\x75\x6E\x69\x70\x69\x78\x65\x6C\x2D\x63\x6F\x6D\x6D\x6F\x6E", $wrappedScript, "\x61\x66\x74\x65\x72"); delete_transient($transient_key); } } add_action('wp_footer', "\x75\x6E\x69\x70\x69\x78\x65\x6C\x5F\x68\x61\x6E\x64\x6C\x65\x5F\x73\x65\x73\x73\x69\x6F\x6E\x5F\x61\x64\x64\x74\x6F\x63\x61\x72\x74\x5F\x6D\x69\x63\x72\x6F\x73\x6F\x66\x74"); 