Forum Discussion

Ken_Chan_95249's avatar
Ken_Chan_95249
Icon for Nimbostratus rankNimbostratus
Jan 07, 2010

Add google analytics code to payload

Hi all,

 

 

I want to add the google analytics code to payload by irules and I have created the following ..

 

 

when HTTP_RESPONSE {

 

set clen [HTTP::header Content-Length]

 

HTTP::collect $clen

 

}

 

 

when HTTP_REQUEST_DATA {

 

 

set google_code " "

 

regsub -all "" [HTTP::payload] $google_code new_payload

 

 

HTTP::payload replace 0 $clen $new_payload

 

 

}

 

 

 

 

 

but it seems not working, does any one has any idea about that ? thank you in advance ..

 

 

3 Replies

  • Hi Ken,

    That's a good start. You could take the second example on the HTTP::collect wiki page (Click here and add a check to see that the response content type contains "text" (or other relevant content-types for you):

      
         if {[HTTP::header "Content-Length"] contains "text" && \  
            [HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] <= 1048576}{  
      

    In HTTP_REQUEST_DATA, you could then insert the Google Javascript using:

    HTTP::payload replace 0 0 $new_payload

    The first digit is the offset. 0 starts the insertion at the beginning. The second digit is the length of the string to replace. 0 replaces nothing.

    Aaron
  • Hi Ken,

     

    Not sure if saw this but here is excellent article regarding adding Google analytics to an existing page.

     

     

    http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=174

     

     

     

    I hope this helps

     

     

    Bhattman

     

     

  • Just for people that would need that in the future, I used HTTP_RESPONSE_DATA instead of HTTP_REQUEST_DATA For the testing on the content, I used if {[HTTP::header "Content-Type"] contains "text" && [HTTP::header exists "Content-Length"] && [HTTP::header "Content-Length"] <= 1048576}{