Eric - 2015-01-11

Trying to add Google analytic code within </head> tag but the rsub replacement is not working as expected.

SecStreamOutBodyInspection on
SecContentInjection on

SecRule STREAM_OUTPUT_BODY "@rsub s/(?i)<\/head>/<script> \ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ \ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), \ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) \ })(window,document,'script','\/\/www.google-analytics.com\/analytics.js','ga'); \ ga('create', 'UA-58XXXXXX', 'auto'); \ ga('send', 'pageview'); \ <\/script><\/head>/" "id:99001,phase:4;t:none,log,pass"

This gets added as:

<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]function(){ (i[r].q=i[r].q[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-58XXXXXX', 'auto'); ga('send', 'pageview'); </script>

</head>ead>

Errors noted:

pipes || are missing. I have tried escaping \|\| but get error restarting apache. Also </head> is not being matched fully as the replacement add "ead>" at the end.

Also how do i add new lines to format the script? I have tried /r/n but doesn't work.

Any help appreciated.