Forum Discussion
kghahremani
Nimbostratus
Aug 19, 2019out of bound error in piwik iRule
I've used iRule for piwik like sample below : https://devcentral.f5.com/s/articles/google-analytics-script-injection-911?t=1566187088612 I've created iRule and iList but whet check ltm log I've...
Aug 19, 2019
I have never used Piwik or Matomo. I think you use Matomo. I updated piwik codes for Matomo. But I 'm not sure if it will work.
google.js (Import to iFile):
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '$static::tracking_id', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->matomo.js (Import to iFile):
<!-- Matomo -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="$static::matomo_url";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', {$static::siteid}]);
var d=document,
g=d.createElement('script'),
s=d.getElementsByTagName('script')[0];
g.;
g.type='text/javascript';
g.async=true;
g.defer=true;
g.src=u+'matomo.js';
s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->iRule:
when RULE_INIT {
set static::tracking_id "Your Google Analytics ID UA-XXXXX-Y"
set static::siteid "XXXXX"
set static::matomo_url "https://matomo.url/ (with slash)"
}
when HTTP_REQUEST {
HTTP::header remove "Accept-Encoding"
}
when HTTP_RESPONSE {
if { [HTTP::header Content-Type] contains "text/html" } {
if { [HTTP::header exists "Content-Length"] } {
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 1000000
}
if { $content_length > 0 } {
HTTP::collect $content_length
}
}
}
when HTTP_RESPONSE_DATA {
set search "</head>"
HTTP::payload replace 0 $content_length [string map [list $search "[subst -nocommands -nobackslashes [ifile get google.js]]</head>"] [HTTP::payload]]
HTTP::release
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects