(function () {
    var cordovaRef = window.PhoneGap || window.cordova || window.Cordova;
    var queue = [];
    var runInterval = 1000;    
    var running = true;
    var runner = null;

    function TagManager() {
    }

    // initialize google analytics with an account ID and the min number of seconds between posting
    //
    // id = the GTM account ID of the form 'GTM-000000'
    // period = the minimum interval for transmitting tracking events if any exist in the queue
    TagManager.prototype.init = function (success, fail, id, period) {
        var timestamp = new Date().getTime();
        queue.push({
            timestamp: timestamp,
            method: 'initGTM',
            success: success,
            fail: fail,
            id: id,
            period: period
        });
        if (!running) runner = setInterval(run, runInterval);
    };

    // log an event
    //
    // category = The event category. This parameter is required to be non-empty.
    // eventAction = The event action. This parameter is required to be non-empty.
    // eventLabel = The event label. This parameter may be a blank string to indicate no label.
    // eventLabel = The event label. This parameter may be a blank string to indicate no label.
    // eventValue = The event value. This parameter may be -1 to indicate no value.
    TagManager.prototype.trackEvent = function (success, fail, category, eventAction, eventLabel, eventValue) {
        var timestamp = new Date().getTime();
        queue.push({
            timestamp: timestamp,
            method: 'trackEvent',
            success: success,
            fail: fail,
            category: category,
            eventAction: eventAction,
            eventLabel: eventLabel,
            eventValue: eventValue
        });
        if (!running) runner = setInterval(run, runInterval);
    };

    // log a page view
    //
    // pageURL = the URL of the page view
    TagManager.prototype.trackPage = function (success, fail, pageURL) {
        setTimeout(function() {
            var timestamp = new Date().getTime();
            queue.push({
                timestamp: timestamp,
                method: 'trackPage',
                success: success,
                fail: fail,
                pageURL: pageURL
            });
            if (!running) runner = setInterval(run, runInterval);
        }, runInterval + 100);
    };

    TagManager.prototype.dispatch = function (success, fail) {
        var timestamp = new Date().getTime();
        queue.push({
            timestamp: timestamp,
            method: 'dispatch',
            success: success,
            fail: fail
        });
        if (!running) runner = setInterval(run, runInterval);
    };

    TagManager.prototype.exit = function (success, fail) {
        var timestamp = new Date().getTime();
        queue.push({
            timestamp: timestamp,
            method: 'exitGTM',
            success: success,
            fail: fail
        });
        if (!running) runner = setInterval(run, runInterval);
    };

    if (cordovaRef && cordovaRef.addConstructor) {
        cordovaRef.addConstructor(init);
    }
    else {
        init();
    }

    function init() {
        if (!window.plugins) {
            window.plugins = {};
        }
        if (!window.plugins.TagManager) {
            window.plugins.TagManager = new TagManager();
        }
    }

    function run() {
        running = true;
        if (queue.length > 0) {
            var item = queue.shift();
            if (item.method === 'initGTM') {
                cordovaRef.exec(item.success, item.fail, 'TagManager', item.method, [item.id, item.period]);
            }
            else if (item.method === 'trackEvent') {
                cordovaRef.exec(item.success, item.fail, 'TagManager', item.method, [item.category, item.eventAction, item.eventLabel, item.eventValue]);
            }
            else if (item.method === 'trackPage') {
                cordovaRef.exec(item.success, item.fail, 'TagManager', item.method, [item.pageURL]);
            }
            else if (item.method === 'dispatch') {
                cordovaRef.exec(item.success, item.fail, 'TagManager', item.method, []);
            }
            else if (item.method === 'exitGTM') {
                cordovaRef.exec(item.success, item.fail, 'TagManager', item.method, []);
            }
        }
        else {
            clearInterval(runner);
            running = false;
        }
    }

    if (typeof module != 'undefined' && module.exports) {
        module.exports = new TagManager();
    }
})();
/* End of Temporary Scope. */
@@ -129,20 +129,16 @@
  = 1000;
-    
 %0A    var
@@ -144,27 +144,28 @@
 r running = 
-tru
+fals
 e;%0A    var r
@@ -173,15 +173,8 @@
 nner
- = null
 ;%0A%0A 
@@ -533,24 +533,96 @@
 , period) %7B%0A
+        runner = setInterval(run, runInterval);%0A        running = true;%0A
         var 
@@ -858,70 +858,8 @@
 %7D);%0A
-        if (!running) runner = setInterval(run, runInterval);%0A
     
@@ -1788,70 +1788,8 @@
 %7D);%0A
-        if (!running) runner = setInterval(run, runInterval);%0A
     
@@ -1941,44 +1941,8 @@
 ) %7B%0A
-        setTimeout(function() %7B%0A    
     
@@ -1987,28 +1987,24 @@
 ();%0A        
-    
 queue.push(%7B
@@ -2008,36 +2008,32 @@
 h(%7B%0A            
- 
-   
 timestamp: times
@@ -2042,36 +2042,32 @@
 mp,%0A            
-    
 method: 'trackPa
@@ -2075,36 +2075,32 @@
 e',%0A            
-   
- 
 success: success
@@ -2093,36 +2093,32 @@
 ccess: success,%0A
-    
             fail
@@ -2137,20 +2137,16 @@
         
-    
 pageURL:
@@ -2166,110 +2166,9 @@
     
- 
-   %7D);%0A            if (!running) runner = setInterval(run, runInterval);%0A        %7D, runInterval + 100
+%7D
 );%0A 
@@ -2439,70 +2439,8 @@
 %7D);%0A
-        if (!running) runner = setInterval(run, runInterval);%0A
     
@@ -2698,25 +2698,24 @@
      %7D);
-%0A
         
 if (!run
@@ -2710,61 +2710,8 @@
     
-if (!running) runner = setInterval(run, runInterval);
 %0A   
@@ -3038,24 +3038,36 @@
 agManager();
+            
 %0A        %7D%0A 
@@ -3092,25 +3092,24 @@
  run() %7B
-%0A
         
 running 
@@ -3096,39 +3096,24 @@
 () %7B        
-running = true;
 %0A        if 
@@ -4028,43 +4028,8 @@
     
-        %7D%0A        %7D%0A        else %7B%0A
     
@@ -4063,32 +4063,36 @@
 r);%0A            
+    
 running = false;
@@ -4088,24 +4088,38 @@
 ng = false;%0A
+            %7D%0A
         %7D%0A  

Change running interval to depend on init and exit