Suppress Tracking of various scripts on test and development environment

11 / Jul / 2010 by Tarun Pareek 0 comments

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,

Hope this code will help 🙂

~Regards,
Tarun
Intelligrape Software

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *