Suppress Tracking of various scripts on test and development environment « Intelligrape Groovy & Grails Blogs

Suppress Tracking of various scripts on test and development environment

Posted by Tarun Pareek

In my recent project, every time the page loads, it loads with lots of scripts making calls to and getting content from googleapis, fb, clixpy, cdn etc. to provide the functionality, due to which the page loads very slowly and this led to the wastage of time to test a certain functionality.

To overcome this problem in test and development environment and at the same time to run those script in the production environment, I added the “suppressTracker” tag that enable or disable the script on the basis of environment on which it is executing or on the basis of session set for tracker.

Step 1 : Create the suppressTracker tag in your tagLib,

import grails.util.Environment;
 
def suppressTracking = {attrs, body ->
        if (Environment.currentEnvironment==Environment.PRODUCTION && !session.suppressTracking){
            out<< body()
        }
}

Step 2 : Add suppressTracker tag on the script which you want to suppress for test and development environment,

<util:suppressTracking>
  <script type="text/javascript">
       Your Script Code ..........
  </script>
</util:suppressTracking>

Hope this code will help :)

~Regards,
Tarun
Intelligrape Software

http://in.linkedin.com/in/tarunpareek

  • Share/Bookmark
This entry was posted on July 11th, 2010 at 1:48 pm and is filed under Grails, Groovy, Javascript/Ajax/JQuery . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply