albacross_get_client_id(), 'plugin_version' => ALBACROSS_PLUGIN_VERSION, ), plugins_url( 'assets/js/albacross-loader.js', ALBACROSS_PLUGIN_FILE ) ); wp_enqueue_script( ALBACROSS_SCRIPT_HANDLE, $loader_url, array(), ALBACROSS_PLUGIN_VERSION, true ); } /** * Build the inline configuration that must run before track.js. * * @return string */ function albacross_get_inline_config() { return sprintf( 'window._nQc=%s;window._nQs=%s;window._nQsv=%s;', wp_json_encode( albacross_get_client_id() ), wp_json_encode( 'WordPress-Plugin' ), wp_json_encode( ALBACROSS_PLUGIN_VERSION ) ); } /** * Add the async attribute to the tracking script tag. * * Done via script_loader_tag rather than the WP 6.3+ strategy argument so the * plugin keeps working on older supported versions of WordPress. * * @param string $tag The script tag. * @param string $handle The script handle. * @param string $src The script source. * @return string */ function albacross_async_script_tag( $tag, $handle, $src ) { if ( ALBACROSS_SCRIPT_HANDLE !== $handle || false !== strpos( $tag, ' async' ) ) { return $tag; } return str_replace( ' src=', ' async src=', $tag ); } /** * Sanitize a Client ID. * * @param mixed $client_id Raw value. * @return string */ function albacross_sanitize_client_id( $client_id ) { if ( ! is_scalar( $client_id ) ) { return ''; } $client_id = preg_replace( '/[^A-Za-z0-9_-]/', '', (string) $client_id ); return substr( (string) $client_id, 0, 64 ); }