*/ public static function defaults(): array { return array( 'consent_enabled' => false, 'consent_region' => 'eu', // eu | us | auto 'consent_layout' => 'card', // card | bar 'consent_position' => 'right', // left | right (card only) 'consent_theme' => 'auto', // auto | light | dark 'consent_title' => __( 'We value your privacy', 'ai-rank-suite' ), 'consent_message' => __( 'We use cookies to understand how this site is used and, with your permission, to measure our marketing. You choose what runs.', 'ai-rank-suite' ), 'consent_accept' => __( 'Accept all', 'ai-rank-suite' ), 'consent_reject' => __( 'Reject all', 'ai-rank-suite' ), 'consent_save' => __( 'Save choices', 'ai-rank-suite' ), 'consent_manage' => __( 'Manage', 'ai-rank-suite' ), 'consent_dns' => __( 'Do not sell or share my personal information', 'ai-rank-suite' ), 'consent_policy' => '', // Privacy policy URL; falls back to WP's privacy page. 'consent_reopen' => true, 'consent_gcm' => true, // Google Consent Mode v2 signals. 'consent_marketing' => false, // Show a Marketing category (ads pixels via snippets). 'consent_expiry' => 180, // days // Bumping this invalidates every consent given under the old text. // A changed cookie policy needs a fresh decision; without a version // the first answer a visitor ever gave would stand forever. 'consent_version' => 1, // Article 7(1): the controller must be able to demonstrate consent. 'consent_log' => true, 'consent_log_days' => 365, ); } /** * Record one decision, so the site can demonstrate it later. * * Called from the front end by an anonymous visitor, so it takes no nonce * and writes nothing a visitor supplies except the flags themselves. The * address and user agent are salted hashes: enough to tell two decisions * from one browser apart, useless for identifying anybody, and useless * outside this site because the salt is the site's own. * * @param array $settings Analytics settings. * @param array $choice analytics|marketing flags and the decision kind. */ /** * How many decisions one visitor may record per hour, and the site in * total per minute. A real visitor makes one or two; a banner re-opened * and re-answered a dozen times is still far under. Anything above is a * script, and a script must not be able to fill the table. */ private const RATE_PER_VISITOR = 20; private const RATE_GLOBAL = 600; /** Identical decision from the same visitor inside this window: update, not insert. */ private const DEDUPE_SECONDS = 300; /** * Only an internal path may be stored as the page a decision was made on. * * The value arrives from an anonymous POST, so it is treated as hostile: no * scheme, no host, no control characters, no leading formula characters, * capped in length. What survives is a path like /pricing/ — the one thing * the record actually needs. */ public static function clean_path( string $raw ): string { $raw = trim( $raw ); if ( '' === $raw ) { return ''; } // A full URL is reduced to its path; a foreign host is not ours to record. if ( preg_match( '#^[a-z][a-z0-9+.-]*://#i', $raw ) || 0 === strpos( $raw, '//' ) ) { $host = (string) wp_parse_url( $raw, PHP_URL_HOST ); $ours = (string) wp_parse_url( home_url(), PHP_URL_HOST ); if ( '' === $host || strtolower( $host ) !== strtolower( $ours ) ) { return ''; } $raw = (string) wp_parse_url( $raw, PHP_URL_PATH ); } // Control characters and anything a spreadsheet would read as a formula. $raw = preg_replace( '/[\x00-\x1F\x7F]/', '', $raw ) ?? ''; $raw = ltrim( $raw, "=+-@\t\r " ); if ( '' === $raw ) { return ''; } if ( '/' !== $raw[0] ) { $raw = '/' . $raw; } return mb_substr( $raw, 0, 191 ); } /** * Record one decision, so the site can demonstrate it later. * * @return true|\WP_Error True when written or updated; WP_Error with a * 429 when the caller is over its rate. */ public static function log( array $settings, array $choice ) { if ( empty( $settings['consent_log'] ) ) { return true; } global $wpdb; $decision = (string) ( $choice['decision'] ?? 'custom' ); if ( ! in_array( $decision, array( 'accept_all', 'reject_all', 'custom' ), true ) ) { $decision = 'custom'; } $salt = defined( 'AUTH_SALT' ) ? (string) AUTH_SALT : ABSPATH; $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( (string) $_SERVER['REMOTE_ADDR'] ) ) : ''; $ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( (string) $_SERVER['HTTP_USER_AGENT'] ) ) : ''; $vh = '' === $ip ? '' : hash( 'sha256', $salt . '|ip|' . $ip ); /* * Rate limits, in transients: cheap, self-expiring, and correct enough * for the purpose — this is a tar pit for scripts, not an accounting * system. Per visitor first, so one abuser cannot spend the site's * global allowance for everybody else. */ $vk = 'airanksuite_cl_v_' . substr( $vh, 0, 32 ); $vn = (int) get_transient( $vk ); if ( '' !== $vh && $vn >= self::RATE_PER_VISITOR ) { return new \WP_Error( 'airanksuite_consent_rate_visitor', 'Too many consent records from this visitor.', array( 'status' => 429 ) ); } $gk = 'airanksuite_cl_g_' . gmdate( 'YmdHi' ); $gn = (int) get_transient( $gk ); if ( $gn >= self::RATE_GLOBAL ) { return new \WP_Error( 'airanksuite_consent_rate_global', 'Too many consent records right now.', array( 'status' => 429 ) ); } if ( '' !== $vh ) { set_transient( $vk, $vn + 1, HOUR_IN_SECONDS ); } set_transient( $gk, $gn + 1, 2 * MINUTE_IN_SECONDS ); $row = array( 'created_at' => current_time( 'mysql', true ), 'decision' => $decision, 'analytics' => ! empty( $choice['analytics'] ) ? 1 : 0, 'marketing' => ! empty( $choice['marketing'] ) ? 1 : 0, 'region' => self::region( $settings ), 'policy_version' => (int) ( $settings['consent_version'] ?? 1 ), 'visitor_hash' => $vh, 'agent_hash' => '' === $ua ? '' : hash( 'sha256', $salt . '|ua|' . $ua ), 'url' => self::clean_path( (string) ( $choice['url'] ?? '' ) ), ); /* * The same visitor making the same decision again within a few minutes * is a double click or a reloaded page, not a second consent. Update * the row's time rather than adding one — the record stays truthful * and a stuck button cannot mint rows. */ $table = Database::consent_log(); if ( '' !== $vh ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $dup = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table} WHERE visitor_hash = %s AND decision = %s AND analytics = %d AND marketing = %d AND policy_version = %d AND created_at >= %s ORDER BY id DESC LIMIT 1", $vh, $decision, $row['analytics'], $row['marketing'], $row['policy_version'], gmdate( 'Y-m-d H:i:s', time() - self::DEDUPE_SECONDS ) ) ); if ( $dup ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->update( $table, array( 'created_at' => $row['created_at'], 'url' => $row['url'] ), array( 'id' => (int) $dup ) ); return true; } } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, $row ); // Retention, enforced where the row lands: one delete per write is // cheaper than a cron that drifts out of step with the setting. $days = max( 30, (int) ( $settings['consent_log_days'] ?? 365 ) ); if ( 0 === wp_rand( 0, 50 ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . Database::consent_log() . ' WHERE created_at < %s', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table name from this plugin's own Database class/adapter, never from input; values go through $wpdb->prepare(). gmdate( 'Y-m-d H:i:s', time() - $days * DAY_IN_SECONDS ) ) ); } return true; } /** * One CSV cell, made safe for a spreadsheet. * * Excel, Numbers and LibreOffice run a cell that starts with = + - @ as a * formula. The path column comes from an anonymous POST, so an attacker * could store "=HYPERLINK(...)" and have a DPO's spreadsheet execute it. * Neutralise with a leading apostrophe, double the quotes, and strip the * control characters that would break a row. */ public static function csv_cell( $value ): string { $v = (string) $value; $v = preg_replace( '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', '', $v ) ?? ''; $v = str_replace( array( "\r\n", "\r", "\n" ), ' ', $v ); if ( '' !== $v && false !== strpos( "=+-@\t", $v[0] ) ) { $v = "'" . $v; } return '"' . str_replace( '"', '""', $v ) . '"'; } /** * The record, summarised for the admin screen. * * @param array $settings Analytics settings. * @return array */ public static function log_summary( array $settings ): array { global $wpdb; $table = Database::consent_log(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $row = $wpdb->get_row( $wpdb->prepare( "SELECT COUNT(*) AS total, SUM(decision = 'accept_all') AS accepted, SUM(decision = 'reject_all') AS rejected, SUM(decision = 'custom') AS custom, SUM(analytics = 1) AS analytics, SUM(marketing = 1) AS marketing, MIN(created_at) AS first_at, MAX(created_at) AS last_at FROM %i", $table ), ARRAY_A ); $version = (int) ( $settings['consent_version'] ?? 1 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $stale = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE policy_version < %d", $version ) ); $total = (int) ( $row['total'] ?? 0 ); return array( 'total' => $total, 'accepted' => (int) ( $row['accepted'] ?? 0 ), 'rejected' => (int) ( $row['rejected'] ?? 0 ), 'custom' => (int) ( $row['custom'] ?? 0 ), 'analytics' => (int) ( $row['analytics'] ?? 0 ), 'marketing' => (int) ( $row['marketing'] ?? 0 ), 'first_at' => (string) ( $row['first_at'] ?? '' ), 'last_at' => (string) ( $row['last_at'] ?? '' ), 'stale' => $stale, 'version' => $version, 'rate' => $total > 0 ? (int) round( 100 * (int) ( $row['accepted'] ?? 0 ) / $total ) : 0, ); } /** * Which posture applies to this request. * * @param array $settings Analytics settings. * @return 'eu'|'us' */ public static function region( array $settings ): string { $mode = (string) ( $settings['consent_region'] ?? 'eu' ); if ( 'auto' !== $mode ) { return 'us' === $mode ? 'us' : 'eu'; } // Auto resolves to the STRICTEST posture unless a trustworthy signal // positively places the visitor somewhere opt-out is the norm. // // Two rules, both learned the hard way: // // 1. Only a header the visitor cannot set counts. CF-IPCOUNTRY is // written by Cloudflare in front of the origin; a request that did // not come through Cloudflare can carry any value it likes, so the // header is only consulted when the site says it is behind a proxy // that guarantees it. X-Country-Code was trusted here and is not // trustworthy: anyone can send it. // 2. Language is not location. en-US is the default on machines all // over the world, and treating it as proof of US residency is how a // European visitor ends up tracked without consent. It no longer // decides anything. // // Everything else stays opt-in. Region detection is a convenience, not // a legal guarantee — a site with real obligations sets the posture by // hand. /** * Which request header, if any, carries a trustworthy country code. * * Empty by default: nothing is trusted until the site owner says the * header is written by their own edge and cannot be spoofed by a * visitor. Return e.g. 'HTTP_CF_IPCOUNTRY' behind Cloudflare. * * @param string $header Server variable name, or '' for none. */ $header = (string) apply_filters( 'airanksuite/consent/country_header', '' ); if ( '' === $header ) { return 'eu'; } $hint = strtoupper( substr( \AiRankSuite\Support\Server::text( $header ), 0, 2 ) ); if ( '' === $hint ) { return 'eu'; } /** * Filter the countries treated as opt-out under automatic mode. * * @param array $codes ISO country codes. */ $optout = (array) apply_filters( 'airanksuite/consent/optout_countries', array( 'US' ) ); return in_array( $hint, array_map( 'strtoupper', $optout ), true ) ? 'us' : 'eu'; } /** * The visitor's stored choices, or null when undecided. * * @return array{analytics: bool, marketing: bool}|null */ public static function choices(): ?array { if ( ! isset( $_COOKIE[ self::COOKIE ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return null; } // A cookie is sender-controlled like any other input, so it is // unslashed and sanitized before anything looks at it. $raw = sanitize_text_field( wp_unslash( (string) $_COOKIE[ self::COOKIE ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a public consent cookie, read on the front end. // Legacy v1 values from 0.98.16. if ( 'yes' === $raw ) { return array( 'analytics' => true, 'marketing' => true ); } if ( 'no' === $raw ) { return array( 'analytics' => false, 'marketing' => false ); } $data = json_decode( $raw, true ); if ( ! is_array( $data ) ) { return null; } return array( 'analytics' => ! empty( $data['analytics'] ), 'marketing' => ! empty( $data['marketing'] ), // Which policy the visitor agreed to. Absent on cookies written // before versioning existed, which is treated as version 1. 'pv' => max( 1, (int) ( $data['pv'] ?? 1 ) ), ); } /** * Has the policy changed since this visitor decided? * * A consent given for one cookie policy does not carry over to a different * one, so a bump to the version re-opens the banner for everybody who * answered under the old text — and only for them. * * @param array $settings Analytics settings. */ public static function stale( array $settings ): bool { $choices = self::choices(); if ( null === $choices ) { return false; } return (int) $choices['pv'] < (int) ( $settings['consent_version'] ?? 1 ); } /** * Must analytics tags be withheld on this request? * * Opt-in: withheld until the visitor allowed analytics. * Opt-out: allowed until the visitor turned analytics off. * * @param array $settings Analytics settings. */ public static function blocks_tracking( array $settings ): bool { if ( empty( $settings['consent_enabled'] ) ) { return false; } $choices = self::choices(); if ( null !== $choices ) { return ! $choices['analytics']; } return 'eu' === self::region( $settings ); // Undecided: EU blocks, US runs. } /** * Google Consent Mode v2 defaults — printed at wp_head priority 1, i.e. * before the gtag loader, which is what makes the signal effective. * * @param array $settings Analytics settings. */ public static function gcm_defaults( array $settings ): void { if ( empty( $settings['consent_enabled'] ) || empty( $settings['consent_gcm'] ) || is_admin() ) { return; } $choices = self::choices(); $optout = 'us' === self::region( $settings ); $an = null !== $choices ? $choices['analytics'] : $optout; $mk = null !== $choices ? $choices['marketing'] : $optout; $state = array( 'ad_storage' => $mk ? 'granted' : 'denied', 'ad_user_data' => $mk ? 'granted' : 'denied', 'ad_personalization' => $mk ? 'granted' : 'denied', 'analytics_storage' => $an ? 'granted' : 'denied', 'functionality_storage' => 'granted', 'security_storage' => 'granted', 'wait_for_update' => 500, ); /* * The handle every tag in the plugin depends on. * * Consent Mode requires this default to execute before any Google tag * loads. Naming the handle and exporting it as a constant is what lets * the analytics module declare that requirement as a dependency rather * than trusting hook order. */ \AiRankSuite\Support\Inline::script( self::GCM_HANDLE, sprintf( 'window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}' . 'gtag("consent","default",%s);', wp_json_encode( $state ) ) ); } /** * The banner, the preference panel, the reopen control and the script. * * @param array $settings Analytics settings. */ /** * Should the banner appear at all on this request? * * Extracted from render() so that the assets and the markup cannot * disagree: a stylesheet enqueued for a banner that never renders is * wasted bytes, and a banner rendered without its stylesheet is worse. * * @param array $settings Analytics settings. */ public static function should_render( array $settings ): bool { if ( empty( $settings['consent_enabled'] ) || is_admin() ) { return false; } $region = self::region( $settings ); $choices = self::choices(); $decided = null !== $choices && ! self::stale( $settings ); if ( $decided && empty( $settings['consent_reopen'] ) && 'us' !== $region ) { return false; } return true; } /** * What the front-end script is told, as an array. * * @param array $settings Analytics settings. * @return array */ public static function config( array $settings ): array { $region = self::region( $settings ); $choices = self::choices(); $decided = null !== $choices && ! self::stale( $settings ); return array( 'cookie' => self::COOKIE, 'days' => max( 1, (int) ( $settings['consent_expiry'] ?? 180 ) ), 'region' => $region, 'gcm' => ! empty( $settings['consent_gcm'] ), 'decided' => $decided, 'pv' => (int) ( $settings['consent_version'] ?? 1 ), 'log' => ! empty( $settings['consent_log'] ) ? esc_url_raw( rest_url( 'airanksuite/v1/consent/record' ) ) : '', 'analytics' => $decided ? (bool) $choices['analytics'] : ( 'us' === $region ), 'marketing' => $decided ? (bool) $choices['marketing'] : ( 'us' === $region ), ); } public static function render( array $settings ): void { if ( empty( $settings['consent_enabled'] ) || is_admin() ) { return; } $region = self::region( $settings ); $choices = self::choices(); // A decision made under an older policy is not a decision any more. $decided = null !== $choices && ! self::stale( $settings ); $reopen = ! empty( $settings['consent_reopen'] ); if ( $decided && ! $reopen && 'us' !== $region ) { return; } $policy = (string) $settings['consent_policy']; if ( '' === $policy && function_exists( 'get_privacy_policy_url' ) ) { $policy = (string) get_privacy_policy_url(); } $layout = 'bar' === ( $settings['consent_layout'] ?? 'card' ) ? 'bar' : 'card'; $position = 'left' === ( $settings['consent_position'] ?? 'right' ) ? 'left' : 'right'; $theme = in_array( $settings['consent_theme'] ?? 'auto', array( 'light', 'dark' ), true ) ? $settings['consent_theme'] : 'auto'; $show_mk = ! empty( $settings['consent_marketing'] ); $t = static fn( string $k ): string => esc_html( (string) ( $settings[ $k ] ?? '' ) ); $cfg = self::config( $settings ); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- every dynamic fragment below is escaped where it is built: $t() runs esc_html(), pref_row() escapes its own fields, URLs go through esc_url(). echo ''; // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped // The persistent control: US gets the legally-worded link, EU a small // cookie button. Both reopen the panel. if ( $reopen || 'us' === $region ) { $label = 'us' === $region ? $t( 'consent_dns' ) : '🍪'; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * The banner's stylesheet and behaviour. * * Separate from render() because the markup is emitted at wp_body_open and * the assets have to be in the head: a cookie banner that paints before * its stylesheet arrives is a column of unstyled text across the top of * the page, on the first view of every new visitor. * * @param array $settings Analytics settings. */ public static function enqueue( array $settings ): void { if ( ! self::should_render( $settings ) ) { return; } \AiRankSuite\Support\Inline::style( 'airanksuite-cmp', self::css() ); \AiRankSuite\Support\Inline::script( 'airanksuite-cmp', 'window.airanksuiteCmp=' . wp_json_encode( self::config( $settings ) ) . ';' . self::js() ); } private static function pref_row( string $id, string $label, string $desc, bool $on, bool $locked ): string { return ''; } /** Dependency-free, token-less (front end has no admin tokens), both themes. */ private static function css(): string { return '.airanksuite-cmp{position:fixed;z-index:99999;font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;--c-bg:#fff;--c-ink:#16161e;--c-ink2:#5b5e6b;--c-line:#e4e5ea;--c-brand:#6b46e5;--c-brand-ink:#fff;--c-track:#d9dbe0}' . '.airanksuite-cmp.is-dark,.airanksuite-cmp.is-auto:not(.is-light){}' . '@media(prefers-color-scheme:dark){.airanksuite-cmp.is-auto{--c-bg:#1c1c23;--c-ink:#e9e9ef;--c-ink2:#a7a9b4;--c-line:#34343f;--c-track:#3a3b46}}' . '.airanksuite-cmp.is-dark{--c-bg:#1c1c23;--c-ink:#e9e9ef;--c-ink2:#a7a9b4;--c-line:#34343f;--c-track:#3a3b46}' . '.airanksuite-cmp.is-hidden{display:none}' . '.airanksuite-cmp.is-card{bottom:20px;max-width:400px;width:calc(100% - 32px)}.airanksuite-cmp.is-card.is-right{right:16px}.airanksuite-cmp.is-card.is-left{left:16px}' . '.airanksuite-cmp.is-bar{left:0;right:0;bottom:0}.airanksuite-cmp.is-bar .airanksuite-cmp-inner{max-width:1100px;margin:0 auto;border-radius:16px 16px 0 0}' . '.airanksuite-cmp-inner{background:var(--c-bg);color:var(--c-ink);border:1px solid var(--c-line);border-radius:16px;padding:20px 20px 16px;box-shadow:0 12px 40px rgba(0,0,0,.22)}' . '.airanksuite-cmp-title{margin:0 0 6px;font-size:16px;font-weight:700;letter-spacing:-.01em}' . '.airanksuite-cmp-text{margin:0 0 14px;color:var(--c-ink2);font-size:13.5px}.airanksuite-cmp-text a{color:var(--c-brand);text-decoration:underline}' . '.airanksuite-cmp-actions{display:flex;gap:8px;flex-wrap:wrap}' . '.airanksuite-cmp-btn{border:1px solid var(--c-line);background:transparent;color:var(--c-ink);border-radius:9px;padding:9px 16px;font:inherit;font-weight:600;font-size:13px;cursor:pointer}' . '.airanksuite-cmp-btn.is-primary{background:var(--c-brand);color:var(--c-brand-ink);border-color:var(--c-brand);box-shadow:0 2px 8px rgba(107,72,232,.3)}.airanksuite-cmp-btn.is-ghost{border-color:transparent;color:var(--c-ink2)}' . '.airanksuite-cmp-btn[hidden]{display:none}' . '.airanksuite-cmp-prefs{display:grid;gap:6px;margin:0 0 14px;padding-top:12px;border-top:1px solid var(--c-line)}.airanksuite-cmp-prefs[hidden]{display:none}' . '.airanksuite-cmp-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 0;cursor:pointer;position:relative}' . '.airanksuite-cmp-row-text{display:grid;gap:1px}.airanksuite-cmp-row-text strong{font-size:13.5px}.airanksuite-cmp-row-text span{font-size:12px;color:var(--c-ink2)}' . '.airanksuite-cmp-check{position:absolute;opacity:0;width:1px;height:1px}' . '.airanksuite-cmp-switch{flex:0 0 auto;width:38px;height:22px;border-radius:99px;background:var(--c-track);position:relative;transition:background .15s}' . '.airanksuite-cmp-switch::after{content:"";position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:#fff;transition:transform .15s;box-shadow:0 1px 2px rgba(0,0,0,.25)}' . '.airanksuite-cmp-check:checked+.airanksuite-cmp-switch{background:var(--c-brand)}.airanksuite-cmp-check:checked+.airanksuite-cmp-switch::after{transform:translateX(16px)}' . '.airanksuite-cmp-row.is-locked{cursor:default;opacity:.75}.airanksuite-cmp-check:focus-visible+.airanksuite-cmp-switch{outline:2px solid var(--c-brand);outline-offset:2px}' . '.airanksuite-cmp-reopen{position:fixed;bottom:16px;z-index:99998;border:0;border-radius:99px;padding:8px 14px;background:#16161e;color:#e9e9ef;font:12px/1 -apple-system,sans-serif;cursor:pointer;opacity:.9}' . '.airanksuite-cmp-reopen.is-right{right:16px}.airanksuite-cmp-reopen.is-left{left:16px}.airanksuite-cmp-reopen[hidden]{display:none}' . '.airanksuite-cmp-reopen.is-text{border-radius:8px;padding:8px 12px;font-size:12px;text-decoration:underline;background:transparent;color:inherit;opacity:.8}' . '@media(max-width:600px){.airanksuite-cmp.is-card{left:8px;right:8px;bottom:8px;max-width:none;width:auto}}'; } private static function js(): string { return '(function(){var C=window.airanksuiteCmp,d=document,box=d.getElementById("airanksuite-cmp"),re=d.getElementById("airanksuite-cmp-reopen");if(!box)return;' . 'var prefs=box.querySelector(".airanksuite-cmp-prefs"),saveBtn=box.querySelector("[data-airanksuite-cmp=save]"),manageBtn=box.querySelector("[data-airanksuite-cmp=manage]");' . 'function cat(n){var i=box.querySelector("[data-airanksuite-cat="+n+"]");return i?!!i.checked:false}' . 'function gcm(a,m){if(!C.gcm||typeof gtag!=="function")return;gtag("consent","update",{analytics_storage:a?"granted":"denied",ad_storage:m?"granted":"denied",ad_user_data:m?"granted":"denied",ad_personalization:m?"granted":"denied"})}' . 'function persist(a,m,k){var v=encodeURIComponent(JSON.stringify({analytics:a?1:0,marketing:m?1:0,v:2,pv:C.pv}));d.cookie=C.cookie+"="+v+";path=/;max-age="+(C.days*86400)+";SameSite=Lax"+(location.protocol==="https:"?";Secure":"");gcm(a,m);' // Record the decision on the server. Fire-and-forget with keepalive: // the visitor is often navigating away in the same moment, and a // consent banner must never delay the page to file its paperwork. . 'if(C.log){try{fetch(C.log,{method:"POST",keepalive:true,headers:{"Content-Type":"application/json"},body:JSON.stringify({analytics:a?1:0,marketing:m?1:0,decision:k||"custom",url:location.pathname})})}catch(e){}}' . 'var wasOn=C.analytics,nowOn=a;C.analytics=a;C.marketing=m;C.decided=true;box.classList.add("is-hidden");if(re)re.hidden=false;' . 'if(nowOn&&!wasOn){location.reload()}}' . 'box.addEventListener("click",function(e){var b=e.target.closest("[data-airanksuite-cmp]");if(!b)return;var k=b.getAttribute("data-airanksuite-cmp");' . 'if(k==="accept"){persist(true,true,"accept_all")}else if(k==="reject"){persist(false,false,"reject_all")}else if(k==="manage"){prefs.hidden=false;saveBtn.hidden=false;manageBtn.hidden=true}else if(k==="save"){persist(cat("analytics"),cat("marketing"),"custom")}});' . 'if(re){re.addEventListener("click",function(){box.classList.remove("is-hidden");re.hidden=true;prefs.hidden=false;saveBtn.hidden=false;manageBtn.hidden=true;' . 'var a=box.querySelector("[data-airanksuite-cat=analytics]"),m=box.querySelector("[data-airanksuite-cat=marketing]");if(a)a.checked=!!C.analytics;if(m)m.checked=!!C.marketing})}' . '})();'; } }