cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
JRahm
Community Manager
Community Manager

Problem this snippet solves:

The following iRule will utilize the Stream profile to auto-inject the required client side Gomez Networks performance measurement JavaScript code. It builds on the GomezInjection and GomezInjectionWithGroupId CodeShare entries in that it provides support for the Page id parameter to allow for page specific grouping of URI's for search within the Gomez Reporting engine. Just like the previous examples, this iRule performs two functions:

First of all, it will serve up the Gomez Javascript bootstrap code so you do not have to come up with a location to store this on one of your servers. In this example, the javascript is included inline in the script. As a consequence, a string substitution has to be made to replace all the braces at runtime. This overcomes a limitation with the BIG-IP command line import utility in it's handling of a large number of embedded braces. An alternate implementation could be to store this script in an external class file and load the contents with a TCL lindex command as seen in Automatic Sorry Page

How to use this snippet:

Steps to Install

  • Gomez Account Id: You need to apply for a Gomez account and obtain your Gomez Application Id. This is typically a 6-character string. You'll need to replace the value of the GOMEZ_APP_ID variable with your correct application id.
  • Build a list of the page mappings that you would like to use and add them to the GOMEZ_PAGEID_LIST TCL list in the HTTP_REQUEST event.
  • Virtual Server: Enable the default Stream filter profile on your Virtual Server. Also, ensure you have a valid HTTP profile configured.
  • HTTP Profile: Set the value of "Response Chunking" in your HTTP Profile to "Rechunk".
  • iRule: Save the iRule to your LTM and add it as a resource to your Virtual Server.

Code :

when RULE_INIT {
  set GOMEZ_APP_ID "XXXXXX";
  set GOMEZ_DEBUG 2;
  set GOMEZ_DEFAULT_PAGE_ID "Unknown";
  
  set GOMEZ_PAGEID_LIST [list \
    "eq / HomePage" \
    "eq /default.aspx HomePage" \
    "starts_with /app1/page1 App1_SubPage1" \
    "starts_with /app1/page2 App1_SubPage2" \
    "starts_with /app1/page3 App1_SubPage3" \
    "starts_with /app2/page1 App2_SubPage1" \
    "contains /forum/tech Forums_Tech" \
    "contains /forum/finance Forums_Finance" \
    "contains /forum/ Forums_Unknown" \
    "ends_with default.aspx Unknown" \
  ];
}
 
when HTTP_REQUEST {

  if { [info exists gomez_page_id] } {
    unset gomez_page_id;
  }
  
  set gws_luri [string tolower [HTTP::uri]]
  
  if { $gws_luri eq "/js/axftag.js" } {
    
    # -----------------------------------------------------------------------
    # Serve up Gomez bootstrap javascript
    # -----------------------------------------------------------------------
    HTTP::respond 200 content [string map {LBR \{ RBR \}} {/*Gomez tag version: 5.0*/var gomez=gomez?gomez:LBRRBR;gomez.h3=function(d, s)LBRfor(var p in s)LBRd[p]=s[p];RBRreturn d;RBR;gomez.h3(gomez,LBRb3:function(r)LBRif(r<=0)return false;return Math.random()<=r&&r;RBR,b0:function(n)LBRvar c=document.cookie;var v=c.match(new RegExp(';[ ]*'+n+'=([^;]*)'));if(!v)v=c.match(new RegExp(n+'=([^;]*)'));if(v)return unescape(v[1]);return '';RBR,c2:function(n,v,e,p,d,s)LBRtryLBRvar t=this,a=location.hostname;var c=n+'='+escape(v)+(e?';expires='+e.toGMTString():'')+(p?';path='+p:';path=/')+(d?';domain='+d:';domain='+a)+(s?';secure':'');document.cookie=c;RBRcatch(e)LBRRBRRBR,z0:function(n)LBRvar t=this;if(n)LBRvar s =t.b0("__g_c");if(!s)return '';var v=s.match(new RegExp(n+':([^\|]*)'));if(v)return unescape(v[1]);return '';RBRelse return '';RBR,z1:function(n,m)LBRvar t=this;if(n)LBRvar s=t.b0("__g_c");if(s)LBRif(s.indexOf(n+':')!=-1)s=s.replace(new RegExp('('+n+':[^\|]*)'),n+':'+m);else s=s==' '?n+':'+m:s+'|'+n+':'+m;t.c2("__g_c",s);RBRelse t.c2("__g_c",n+':'+m);RBR;RBRRBR);if(gomez.wrate)LBRgomez.i0=gomez.z0('w');if(gomez.i0)LBRgomez.runFlg=parseInt(gomez.i0)>0?true:false;RBRelse if(gomez.b3(parseFloat(gomez.wrate)))LBRgomez.runFlg=true;gomez.z1('w',1);RBRelseLBRgomez.runFlg=false;gomez.z1('w',0);RBRRBRelse if(gomez.wrate==undefined)LBRgomez.runFlg=true;gomez.z1('w',1);RBRelseLBRgomez.runFlg=false;gomez.z1('w',0);RBR;if(gomez.runFlg)LBRgomez.h1=function(v,d)LBRreturn v?v:dRBR;gomez.gs=gomez.h1(gomez.gs,new Date().getTime());gomez.acctId=gomez.h1(gomez.acctId,'');gomez.pgId=gomez.h1(gomez.pgId,'');gomez.grpId=gomez.h1(gomez.grpId, '');gomez.E=function(c)LBRthis.s=c;RBR;gomez.E.prototype=LBRg1:function(e)LBRvar t=gomez,i=t.g6(e);if(i)i.e=t.b5();RBRRBR;gomez.L=function(m)LBRthis.a=m;RBR;gomez.L.prototype=LBRg2:function(m)LBRvar t=gomez,n=t.b5();var s=document.getElementsByTagName(m);var e=t.k;if(m=='script')e=t.j;if(m=='iframe')e=t.l;if(s)LBRvar l=s.length;for(var i=0;i<\/scr"+"ipt>");else t.h5(s);RBR;t.b=t.z0('g');RBR,h7:function()LBRvar t=gomez,u=t.tloc?t.tloc:location.protocol+'//'+t.acctId+'.t.axf8.net/js/gtag5.js';if(t.gSfr)document.write("<\/scr"+"ipt>");else t.h5(u);RBR,n0:function(h)LBRvar t=gomez,f=new Date(t.gt()+946080000000),g=t.b0('__g_u');t.n1=h;t.z1('h',h);if(g&&g!='1'&&g.indexOf('NaN')==-1&&g.indexOf('undefined')==-1)LBRvar r=g.split('_');g=''+r[0]+'_'+r[1]+'_'+r[2]+'_'+r[3]+'_'+r[4]+'_'+r[5]+'_'+h;t.c2('__g_u',g,f);RBR;RBR,b1:function(v,s,q,f)LBRvar t=this;if(t._a)return;if(t.b3(v))LBRt._w=true;t.a=1;var p=parseFloat(s/v);if(t.b3(p))LBRt.x=true;t.a=3;RBR;RBR;t.d=true;t.z1('a',t.a);t.z1('e',v);t.z1('f',s);t.gc.i=v;t.gc.j=s;t.h4(v,s,q,f);if(t._w)LBRt.h7();t._a=true;RBR;RBR,b2:function(v,s)LBRvar t=this,f=new Date(t.gt()+946080000000),g=''+v+'_'+s;if(t._a)return;t.c2('__g_u',g,f);t.gc.c=v;t.gc.d=s;t.z1('c',v);t.z1('d',s);RBR,h4:function(o,p,q,d)LBRvar t=this,f=new Date(t.gt()+946080000000),g=t.b0('__g_u');if(g&&g!='1'&&g.indexOf('NaN')==-1&&g.indexOf('undefined')==-1)LBRvar r=g.split('_'),s;if(d)s=d;else if(q&&q>=0)s=new Date(t.gt()+parseInt(q*86400000)).getTime();elseLBRq=5;s=new Date(t.gt()+432000000).getTime();RBR;g=''+r[0]+'_'+r[1]+'_'+o+'_'+p+'_'+q+'_'+s;t.c2('__g_u',g,f);RBR;RBR,gt:function()LBRreturn new Date().getTime()RBR,b5:function()LBRreturn new Date().getTime()-gomez.gsRBR,b6:function()LBRvar t=gomez;t.p=t.b5();RBR,f8:function()LBRvar t=this;if(t.pollId1)clearInterval(t.pollId1);if(t.pollId2)clearInterval(t.pollId2);if(t.pollId3)clearInterval(t.pollId3);if(t.pollId4)clearInterval(t.pollId4);RBR,b7:function()LBRvar t =gomez;t.f8();t.q=t.b5();RBR,c7:function(u, s)LBRvar t=this;t.m=u;t.s=s;RBR,c8:function()LBRvar t=gomez,n=t.b5(),l=document.images.length;if(l>t._h)LBRfor(var i=t._h; i20) n=n.substring(0,20);var t=this,f=t.u;if(p==3)LBRf[f.length]=LBR'n':'a','a':n,'b':b,'e':p,'f':undefinedRBR;RBRelseLBRf[f.length]=LBR'n':'a','a':n,'b':t.b5(),'e':p,'f':bRBR;RBRRBR,customValue:function(n,v)LBRvar t=this;if(typeof(v)!='number')LBRreturn;RBRt.f6(n,3,v);RBR,d8:function(e)LBRif(gomez.gIE)return e.srcElement||LBRRBR;else return e.currentTarget||e.target||LBRRBR;RBR,e2:function(e,p,f,c)LBRvar n='on'+p;if(e.addEventListener)e.addEventListener(p,f,c);else if(e.attachEvent)e.attachEvent(n, f);elseLBRvar x=e[n];if(typeof e[n]!='function')e[n]=f;else e[n]=function(a)LBRx(a);f(a);RBR;RBRRBR,i1:function()LBRvar d =window.document, done=false,i2=function ()LBRif(!done)LBRdone=true;gomez.b6();gomez.a9();RBRRBR;(function ()LBRtryLBRd.documentElement.doScroll('left');RBRcatch(e)LBRsetTimeout(arguments.callee, 50);return;RBRi2();RBR)();d.onreadystatechange=function()LBRif(d.readyState=='complete')LBRd.onreadystatechange=null;i2();RBRRBR;RBR,g7:function()LBRtryLBRvar t=gomez;t.gc.a=t.acctId;/*@cc_on t.gIE=true;@*/if(t.gIE)LBRt.i1();window.attachEvent('onload', t.b7);RBRelse if(t.gSfr)LBRvar m=setInterval(function()LBRif(/loaded|complete/.test(document.readyState))LBRclearInterval(m);delete m;t.b6();t.b7();RBRRBR, 10);RBRelse if(window.addEventListener)LBRwindow.addEventListener('DOMContentLoaded', t.b6, false);window.addEventListener('load', t.b7, false);RBRelse return;t.c8();t.pollId1=setInterval(t.c8, 10);gomez.L.m['link'].g2('link');t.pollId3=setInterval("gomez.L.m['link'].g2('link')", 10);gomez.L.m['iframe'].g2('iframe');t.pollId4=setInterval("gomez.L.m['iframe'].g2('iframe')", 10);if(!t.gIE)t.a9();RBRcatch(e)LBRreturn;RBRRBRRBR);gomez.h2();gomez.g7();RBR}] "Content-Type" "application/x-javascript" "Cache-Control" "max-age=86400";

  } else {
    
    # -----------------------------------------------------------------------
    # search lookup table to determine pageid
    # -----------------------------------------------------------------------
    if { ([llength $::GOMEZ_PAGEID_LIST] == 0) && [info exists ::GOMEZ_DEFAULT_PAGEID] } {
      
      # ---------------------------------------------------------------------
      # If the pageid list is empty and there is a default page id, use that for
      # all requests
      # ---------------------------------------------------------------------
      #set gomez_page_id $::GOMEZ_DEFAULT_PAGEID;
      
    } else {

      # ---------------------------------------------------------------------
      # Loop through the page id list and look for a match.
      # ---------------------------------------------------------------------
      foreach {mapping} $::GOMEZ_PAGEID_LIST {
        
        if { $::GOMEZ_DEBUG > 2 } { log local0. "Testing mapping ${mapping};" };

        #set gws_def_comp "contains";
        set gws_tokens [split $mapping " "]
        set gws_op [lindex $gws_tokens 0];
        set gws_match [lindex $gws_tokens 1];
        set gws_pageid [lindex $gws_tokens 2];
        set gws_found_match 0;
        
        # -------------------------------------------------------------------
        # attempt to process the comparison.  Catch any exceptions and treat
        # them like a false match.
        # -------------------------------------------------------------------
        set error [catch { set gws_found_match [expr \$gws_luri $gws_op \$gws_match]; }];
        
        if { $gws_found_match } {
          
          if { $::GOMEZ_DEBUG > 0 } { log local0. "Found match with ${gws_match} for uri ${gws_luri};" };
          set gomez_page_id $gws_pageid;
          break;
        }
      }
    }
    
    if { [info exists gomez_page_id] } {
      
      if { $::GOMEZ_DEBUG > 1 } { log local0. "URI: [HTTP::uri]"; }
      # ---------------------------------------------------------------------
      # Prevent the server from sending a compressed response
      # remove the compression offerings from the client
      # ---------------------------------------------------------------------
      if { [HTTP::header exists "Accept-Encoding"] } {
        HTTP::header remove "Accept-Encoding";
      }
      
      # ---------------------------------------------------------------------
      # Don't allow response data to be chunked
      # ---------------------------------------------------------------------
      if { [HTTP::version] eq "1.1" } {
        
        # -------------------------------------------------------------------
        # Force downgrade to HTTP 1.0, but still allow keep-alive connections.
        # Since HTTP 1.1 is keep-alive by default, and 1.0 isn't,
        # we need make sure the headers reflect the keep-alive status.
        # -------------------------------------------------------------------
        
        if { [HTTP::header is_keepalive] } {
          HTTP::header replace "Connection" "Keep-Alive";
        }
      }
    }
  }
}

 when HTTP_RESPONSE {
   
  # -------------------------------------------------------------------------
  # Stream filter is disabled by default
  # -------------------------------------------------------------------------
  STREAM::disable;
   
  if { ([HTTP::header Content-Type] starts_with "text/html") && ([HTTP::status] == 200) } {
    if { $::GOMEZ_DEBUG > 1 } { log local0. "Adding Gomez JavaScript"; }
    # -------------------------------------------------------------------------
    # Only process stream replacement if a valid page (uri) was requested and the content type is html.
    # -------------------------------------------------------------------------
    if { [info exists gomez_page_id] && ([HTTP::header value "Content-Type"] contains "text/html") } {
       
      set gomez_client [subst { 
  
Version history
Last update:
‎17-Mar-2015 14:22
Updated by:
Contributors