Skip to content

Instantly share code, notes, and snippets.

@emmanueltissera
Created December 4, 2015 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanueltissera/3c6d0d45a62c8038ae33 to your computer and use it in GitHub Desktop.
Save emmanueltissera/3c6d0d45a62c8038ae33 to your computer and use it in GitHub Desktop.
Excluding internal traffic in Google Tag Manager (HelperFunction to check exclusion)
@functions {
public static string TrackThisPage()
{
if (Request.QueryString["ignoreGTM"] != null && Request.QueryString["ignoreGTM"] == "false")
{
return "true";
}
else if ((Request.Cookies["ignorePageViews"] != null && Request.Cookies["ignorePageViews"].Value == "true") ||
(Request.QueryString["ignoreGTM"] != null && Request.QueryString["ignoreGTM"] == "true") ||
Request.Path.EndsWith("ignore", StringComparison.InvariantCultureIgnoreCase) ||
Request.Url.Host.Contains(".local"))
{
return "false";
}
return "true";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment