/**
 * @license Angulartics v0.17.2
 * (c) 2013 Luis Farzati http://luisfarzati.github.io/angulartics
 * Piwik 2.1.x update contributed by http://github.com/highskillz
 * License: MIT
 */

/* global _paq */

(function(angular) {
    'use strict';

    /**
     * @ngdoc overview
     * @name angulartics.piwik
     * Enables analytics support for Piwik (http://piwik.org/docs/tracking-api/)
     */
    angular.module('angulartics.piwik', ['angulartics'])
        .config(['$analyticsProvider',
            function($analyticsProvider) {

                $analyticsProvider.settings.pageTracking.trackRelativePath = true;

                // Add piwik specific trackers to angulartics API

                // scope: visit or page. Defaults to 'page'
                $analyticsProvider.api.setCustomVariable = function(varIndex, varName, value, scope) {
                    if (window._paq) {
                        scope = scope || 'page';
                        _paq.push(['setCustomVariable', varIndex, varName, value, scope]);
                        _paq.push(['trackPageView']);
                    }
                }

                // trackSiteSearch(keyword, category, [searchCount])
                $analyticsProvider.api.trackSiteSearch = function(keyword, category, searchCount) {

                    // keyword is required
                    if (window._paq && keyword) {

                        var params = ['trackSiteSearch', keyword, category || false];

                        // searchCount is optional
                        if (angular.isDefined(searchCount)) {
                            params.push(searchCount);
                        }

                        _paq.push(params);
                    }
                };

                // logs a conversion for goal 1. revenue is optional
                // trackGoal(goalID, [revenue]);
                $analyticsProvider.api.trackGoal = function(goalID, revenue) {
                    if (window._paq) {
                        _paq.push(['trackGoal', goalID, revenue || 0]);
                    }
                };

                // Set default angulartics page and event tracking

                // $analytics.setUsername(username)
                $analyticsProvider.registerSetUsername(function(username) {

                    if (window._paq) {
                        _paq.push(['setUserId', username]);
                        _paq.push(['trackPageView']);
                    }
                });

                // $analytics.setAlias(alias)
                // $analyticsProvider.registerSetAlias(function(param) {
                //     // TODO: No piwik corresponding function found. Use setCustomVariable instead
                // });

                // $analytics.setUserProperties(properties)
                // $analyticsProvider.registerSetUserProperties(function(param) {
                //     // TODO: No piwik corresponding function found. Use setCustomVariable instead
                // });

                // locationObj is the angular $location object
                // TODO: Need a way for this to receive the title for the page
                $analyticsProvider.registerPageTrack(function(path, locationObj) {

                    if (window._paq) {
                        // _paq.push(['setDocumentTitle', 'TODO']);
                        _paq.push(['setCustomUrl', path]);
                        _paq.push(['trackPageView']);
                    }
                });

                // trackEvent(category, event, [name], [value])
                $analyticsProvider.registerEventTrack(function(action, properties) {

                    if (window._paq) {
                        // PAQ requires that eventValue be an integer, see: http://piwik.org/docs/event-tracking/
                        if (properties.value) {
                            var parsed = parseInt(properties.value, 10);
                            properties.value = isNaN(parsed) ? 0 : parsed;
                        }

                        _paq.push(['trackEvent', properties.category, action, properties.label, properties.value]);
                    }
                });

            }
        ]);
})(angular);

@@ -487,16 +487,35 @@
 ovider',
+ '$windowProvider',
 %0A       
@@ -546,19 +546,90 @@
 Provider
-) %7B
+, $windowProvider) %7B%0A                var $window = $windowProvider.$get();
 %0A%0A      
@@ -952,32 +952,33 @@
             if (
+$
 window._paq) %7B%0A 
@@ -1041,32 +1041,40 @@
                 
+$window.
 _paq.push(%5B'setC
@@ -1140,32 +1140,40 @@
                 
+$window.
 _paq.push(%5B'trac
@@ -1217,32 +1217,33 @@
                %7D
+;
 %0A%0A              
@@ -1457,32 +1457,33 @@
             if (
+$
 window._paq && k
@@ -1790,32 +1790,40 @@
                 
+$window.
 _paq.push(params
@@ -2080,32 +2080,33 @@
             if (
+$
 window._paq) %7B%0A 
@@ -2431,32 +2431,33 @@
             if (
+$
 window._paq) %7B%0A 
@@ -2471,32 +2471,40 @@
                 
+$window.
 _paq.push(%5B'setU
@@ -2539,32 +2539,40 @@
                 
+$window.
 _paq.push(%5B'trac
@@ -3381,32 +3381,33 @@
             if (
+$
 window._paq) %7B%0A 
@@ -3432,16 +3432,24 @@
      // 
+$window.
 _paq.pus
@@ -3497,32 +3497,40 @@
                 
+$window.
 _paq.push(%5B'setC
@@ -3564,32 +3564,40 @@
                 
+$window.
 _paq.push(%5B'trac
@@ -3827,16 +3827,17 @@
     if (
+$
 window._
@@ -4172,32 +4172,32 @@
              %7D%0A%0A
-
                 
@@ -4196,32 +4196,40 @@
                 
+$window.
 _paq.push(%5B'trac

Use $window to access globals in piwik plugin