Permalink
Browse files

insert before and after regexp to allow to select the place in the pa…

…ge to insert the top and bottom script
  • Loading branch information...
1 parent 85402b3 commit baceb7755be0a1cfd47164db1b841a41f7a159af @taasaa taasaa committed Oct 17, 2011
Showing with 6 additions and 4 deletions.
  1. +3 −3 config/clicktale.yml
  2. +3 −1 lib/astrails/clicktale/controller.rb
View
@@ -18,9 +18,9 @@ default: &default
if(typeof ClickTale=="function") ClickTale(889,1,"www02");
</script>
<!-- ClickTale end of Bottom part -->'
- #do_not_replace: !ruby/regexp "/Not to record when this text is present on the page/i"
- #insert_before: !ruby/regexp "/div.*content/"
- #insert_after: !ruby/regexp "/h1/"
+ #do_not_replace: !ruby/regexp /Not to record when this text is present on the page/i
+ #insert_after: !ruby/regexp /The top part of the script goes after this regexp, by default after opening <body> tag/
+ #insert_before: !ruby/regexp /The bottom part of the script goes before this regexp, by default before closing </body> tag/
#allowed_addresses: "75.125.82.64/26,50.97.162.64/26"
do_not_process_cookie_name: "WRUID"
do_not_process_cookie_value: 0
@@ -27,7 +27,9 @@ def clicktale(opts = {})
def clicktaleize
res = yield
if clicktale_enabled?
- response.body.sub!(/(\<body\>)/, "\\1\n#{clicktale_config[:top]}").sub!(/(\<\/body\>)/, "#{clicktale_bottom}\n\\1")
+ top_regexp = clicktale_config[:insert_after] || /(\<body\>)/
+ bottom_regexp = clicktale_config[:insert_before] || /(\<\/body\>)/
+ response.body.sub!(top_regexp) { |match| match + "\n" + clicktale_config[:top] }.sub!(bottom_regexp) { |match| clicktale_bottom + "\n" + match }
cache_page(nil, "/clicktale/#{clicktale_cache_token}")
end
res

0 comments on commit baceb77

Please sign in to comment.