[Developers] How to get the referrer after consent has been given?
Since version 3.0.0, the module provides the AcbReferrerCookie API to retrieve referrer information stored before a consent choice is made.
In version 4.3.0, only the referrer’s host is stored, not its complete URL. This information is only available if the request supplied a valid absolute referrer header and the module could store it before a choice was already present. getReferrer() returns null when no value is available. Early versions of this API could store the complete URL: do not assume the same format across all versions.
The API does not check consent itself. Before using this value in your processing, check that the visitor has authorized your module and the relevant purposes. Usage example:
// Check if the module is installed and enabled
if (Module::isInstalled('pm_advancedcookiebanner') && Module::isEnabled('pm_advancedcookiebanner')) {
// Get an instance, and check that we are using a version that supports storing the referrer
$moduleInstance = Module::getInstanceByName('pm_advancedcookiebanner');
if (version_compare($moduleInstance->version, '3.0.0', '>=')) {
// Get the referrer and do your magic
$referrer = AcbReferrerCookie::getReferrer();
// [...]
// Once you have handled this value, you MUST clear the cookie value to avoid multiple reportings
AcbReferrerCookie::remove();
}
}
After processing the value, call AcbReferrerCookie::remove() as shown to expire the cookie and avoid reporting the same referrer repeatedly. This example does not replace your module’s consent checks.