Use 3-day cookie expiry when analytics consent is denied (v1.3.2)

Denied consent was being stored with the full 365-day expiry, preventing
the banner from re-appearing for users who initially declined. Now when
analytics is denied the cookie expires in 3 days so those users are
re-prompted automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 07:57:11 +01:00
parent 68e7a6ac35
commit cde149467a
2 changed files with 5 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
* Plugin Name: ATT Consent * Plugin Name: ATT Consent
* Plugin URI: https://github.com/att-consent/att-consent * Plugin URI: https://github.com/att-consent/att-consent
* Description: Google Consent Mode v2 cookie consent with session attribution preservation, custom script management, and full gtag.js/GTM support. * Description: Google Consent Mode v2 cookie consent with session attribution preservation, custom script management, and full gtag.js/GTM support.
* Version: 1.3.1 * Version: 1.3.2
* Requires at least: 6.0 * Requires at least: 6.0
* Requires PHP: 7.4 * Requires PHP: 7.4
* Author: ATT Consent * Author: ATT Consent
@@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
define( 'ATT_CC_VERSION', '1.3.1' ); define( 'ATT_CC_VERSION', '1.3.2' );
define( 'ATT_CC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'ATT_CC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ATT_CC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'ATT_CC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'ATT_CC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'ATT_CC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

View File

@@ -121,11 +121,13 @@ var AttConsent = (function() {
/** /**
* Store consent choices in a first-party cookie. * Store consent choices in a first-party cookie.
* If analytics is denied, use a short 3-day expiry so the banner re-appears
* automatically rather than locking a denial in for a year.
* *
* @param {Object} categories Consent categories. * @param {Object} categories Consent categories.
*/ */
function setConsentCookie(categories) { function setConsentCookie(categories) {
var days = config.consent_expiry || 365; var days = categories.analytics ? (config.consent_expiry || 365) : 3;
var expires = new Date(Date.now() + days * 864e5).toUTCString(); var expires = new Date(Date.now() + days * 864e5).toUTCString();
var value = encodeURIComponent(JSON.stringify(categories)); var value = encodeURIComponent(JSON.stringify(categories));
var cookie = 'att_cc_consent=' + value + var cookie = 'att_cc_consent=' + value +