hash === '') { if ($config->debug) { JavaScripts::enqueueDebugNotice('RTB Panel Connector: Tagging hash is not configured, pixel will not be loaded.'); } return; } $init = InitEvent::getEventBody($config->hash, $config->dc); $srcUrl = self::CDN_URL . rawurlencode($config->hash) . '.js'; $body = JavaScripts::bootstrapQueueJs(); $body .= JavaScripts::bootstrapDebugJs(); $body .= 'if(dbg){try{console.log("[RTB Panel Connector] init",'.wp_json_encode($init).');}catch(e){}}'; $body .= 'q.push('.wp_json_encode($init).');'; $body .= 'var f=d.getElementsByTagName("script")[0],c=d.createElement("script");c.async=true;c.src='.wp_json_encode($srcUrl).';f.parentNode.insertBefore(c,f);'; $handle = JavaScripts::registerInlineHandle('rtb-panel-init', false); wp_add_inline_script($handle, JavaScripts::wrapIife($body, 'w,d,dbg', 'window,document,' . ($config->debug ? 'true' : 'false'))); } private static function getEventBody(string $hash, string $dc): array { return [ 'eventType' => self::EVENT_TYPE, 'value' => $hash, 'dc' => $dc, ]; } private static function getConfig(): object { $options = get_option(Settings::OPTION_NAME, array()); $debug = !empty($options['debug']); $hash = isset($options['tagging_hash']) ? trim((string) $options['tagging_hash']) : ''; $dc = isset($options['dc']) ? (string) $options['dc'] : Consts::DATA_CENTER_AMS; return (object) [ 'debug' => $debug, 'hash' => $hash, 'dc' => $dc, ]; } }