CFLib.org – Common Function Library Project

hasDoNotTrackHeader()

Last updated December 04, 2013

author

Indy Griffiths

Version: 1 | Requires: CF9 | Library: CFMLLib

Description:
This UDF will return true if the user has opted out of tracking via the Do Not Track header. The "Do Not Track" HTTP header is a privacy option provided by some browsers indicating that the user has opted out of tracking (such as analytics or behavioural advertising).

Return Values:
Returns a boolean indicating if the header was found and set to 1

Example:

<cfif NOT hasDoNotTrackHeader()>
    <!--- Analytics code goes here --->
</cfif>

Parameters:

No arguments.

Full UDF Source:

/**
 * Support for the &quot;Do Not Track&quot; HTTP header
 * v1.0 by Indy Griffiths
 * v1.1 by Adam Cameron slight performance optimisation and rename
 * 
 * @return Returns a boolean indicating if the header was found and set to 1 
 * @author Indy Griffiths (indy@indygriffiths.com) 
 * @version 1.1, December 4, 2013 
 */
function hasDoNotTrackHeader() {
    var requestHeaders = getHttpRequestData().headers;
    return structKeyExists(requestHeaders, "DNT") && requestHeaders.DNT == 1;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson