Google Analytics script injection
Updated Jun 06, 2023
Version 2.0Was this article helpful?
We arrived at a solution using HTML profiles - am I overlooking any major downsides to this approach?
HTML profile (abbreviated):
ltm profile html /Common/html-ga {
app-service none
content-detection disabled
content-selection { application/xhtml+xml text/xhtml text/html }
defaults-from /Common/html
description none
rules {
/Common/GT-Private
/Common/GA-Private
}
}
ltm html-rule tag-append-html /Common/GT-Private {
action {
text ""
}
description "Google Tag Manager"
match {
tag-name body
}
}
ltm html-rule tag-prepend-html /Common/GA-Private {
action {
text ""
}
description "Google Analytics"
match {
tag-name /head
}
}
Sample iRule (optional and abbreviated):
when HTTP_REQUEST {
set disable_html 0
switch -glob [string tolower [HTTP::uri]] {
/secure_app* {
special case for app that leaks data in URLs
pool secure_app
set disable_html 1
} /legacy_app/pagenotfound/* {
... special case for app that redirects 404s ...
pool legacy_app
set disable_html 1
} default {
... normal logic ...
pool main_app
}
}
}
when HTTP_RESPONSE {
if { [HTTP::status] == 404 || [HTTP::status] == 403 || $disable_html == 1 }{
HTML::disable
}
}