array( 'googletagmanager.com/gtag/js', 'google-analytics.com', 'static.hotjar.com', 'clarity.ms' ), 'marketing' => array( 'connect.facebook.net', 'googleadservices.com', 'doubleclick.net', 'snap.licdn.com', 'analytics.tiktok.com' ), ); function nodd_settings() { return wp_parse_args( get_option( NODD_OPTION, array() ), array( 'host' => NODD_DEFAULT, 'site' => '', 'block' => 1, 'policy' => 1 ) ); } function nodd_ready() { $s = nodd_settings(); return '' !== $s['host'] && '' !== $s['site']; } function nodd_center_url() { $s = nodd_settings(); return $s['host'] . '/p/' . rawurlencode( $s['site'] ); } /* Front end */ // First thing in , so Google Consent Mode defaults to denied before any Google tag runs. add_action( 'wp_head', function () { if ( ! nodd_ready() ) { return; } $s = nodd_settings(); wp_print_script_tag( array( 'src' => $s['host'] . '/w.js', 'data-site' => $s['site'] ) ); }, 1 ); function nodd_category( $src ) { foreach ( NODD_TRACKERS as $category => $needles ) { foreach ( $needles as $needle ) { if ( false !== strpos( (string) $src, $needle ) ) { return $category; } } } return null; } // Same tag, held back: w.js swaps it for a live one once the category is allowed. add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) { if ( is_admin() || ! nodd_ready() || ! nodd_settings()['block'] ) { return $tag; } $category = nodd_category( $src ); if ( ! $category ) { return $tag; } // Only the external tag (the one with src); inline helper scripts printed with it stay as they are. return preg_replace( '/]*\bsrc=)/', '