of public pages. */ class Strabber_Tracker { const CLIENT_URL = 'https://cdn.client.strabber.com/client.js'; public static function init() { add_action('wp_head', [__CLASS__, 'print_snippet'], 1); } public static function print_snippet() { $site_id = Strabber_Options::site_id(); if ($site_id === '' || !self::should_record()) { return; } $script = sprintf( "window.strabber||(function(d){window.strabber=function(){strabber.commands.push(arguments)};window.strabber.commands=[];var s=d.createElement('script');s.async=true;s.type='text/javascript';s.src=%s;d.getElementsByTagName('head')[0].appendChild(s);})(document);strabber('start',%s);", wp_json_encode(self::CLIENT_URL), wp_json_encode($site_id) ); echo "\n\n"; wp_print_inline_script_tag($script); echo "\n"; } private static function should_record() { $should_record = true; if (is_user_logged_in()) { $user = wp_get_current_user(); if (array_intersect((array) $user->roles, Strabber_Options::exclude_roles())) { $should_record = false; } } /** * Filters whether the Strabber snippet is printed on the current request. * * @param bool $should_record */ return (bool) apply_filters('strabber_should_record', $should_record); } }