ÿþ/ / / / / / /  
 / /   g a A d d o n s . j s  
 / /   	 A u t h o r :   S t é p h a n e   H a m e l   -   s h a m e l 6 7 @ g m a i l . c o m   -   h t t p : / / i m m e r i a . n e t  
 / /     C o n t r i b u t o r s :  
 / / 	 -   A n d y   E d m o n d s   -   h t t p : / / a l w a y s b e t e s t i n g . c o m  
 / / 	 -   D a m o n   G u d a i t i s   -   h t t p : / / w w w . d a m o n g u d a i t i s . c o m /  
 / / 	  
 / / / / / / /  
 / /   L i c e n s e :   V e r s i o n :   M P L   1 . 1  
 / /   T h e   c o n t e n t s   o f   t h i s   f i l e   a r e   s u b j e c t   t o   t h e   M o z i l l a   P u b l i c   L i c e n s e   V e r s i o n  
 / /   1 . 1   ( t h e   " L i c e n s e " ) ;   y o u   m a y   n o t   u s e   t h i s   f i l e   e x c e p t   i n   c o m p l i a n c e   w i t h  
 / /   t h e   L i c e n s e .   Y o u   m a y   o b t a i n   a   c o p y   o f   t h e   L i c e n s e   a t  
 / /   h t t p : / / w w w . m o z i l l a . o r g / M P L /  
 / /  
 / /   S o f t w a r e   d i s t r i b u t e d   u n d e r   t h e   L i c e n s e   i s   d i s t r i b u t e d   o n   a n   " A S   I S "   b a s i s ,  
 / /   W I T H O U T   W A R R A N T Y   O F   A N Y   K I N D ,   e i t h e r   e x p r e s s   o r   i m p l i e d .   S e e   t h e   L i c e n s e  
 / /   f o r   t h e   s p e c i f i c   l a n g u a g e   g o v e r n i n g   r i g h t s   a n d   l i m i t a t i o n s   u n d e r   t h e  
 / /   L i c e n s e .  
 / /  
 / /   C h a n g e l o g :  
 / /     v 2 . 5   -   J u n .   1 s t   2 0 0 9   -   M a k e   s u r e   t o   l o a d   a t   " o n l o a d " ,   r e w r i t t e n   a s   a n   o b j e c t  
 / /     v 2 . 4   -   A p r .   2 1 s t   2 0 0 9   -   F i x   t r a c k P a g e v i e w ( )   s y n t a x  
 / /     v 2 . 3   -   A p r .   1 0 t h   2 0 0 9   -   F i x   l o g i c   i s s u e s .   A d d   t r a c k i n g   o f   m a i l t o   l i n k s .   A l l o w   t r a c k e r   t o   b e   n a m e d   s o m e t h i n g   e l s e   t h a n   p a g e T r a c k e r  
 / /     v 2 . 2   -   M a r .   2 0 n d   2 0 0 9   -   F i x   i s s u e   w i t h   t r a c k i n g   d o w n l o a d   d o c s   o n   c u r r e n t   d o m a i n  
 / /     v 2 . 1   -   J a n .   2 2 n d   2 0 0 9   -   S e t   b U s e E v e n t F o r O u t b o u t   a n d   b U s e r E v e n t F o r D o w n l o a d   t o   t o g g l e   u s e   o f   E v e n t s   o r   P a g e   V i e w s  
 / /   	 v 2 . 0   -   J a n .   2 0 0 9   -   U s e   G o o g l e   A n a l y t i c s   E v e n t s   t o   t r a c k   d o w n l o a d s   a n d   e x t e r n a l   l i n k s  
 / /     v 1 . 0   -   I n s p i r e d   b y   t h e   w o r k   o f   J u s t i n   C u t r o n i   -   G o o g l e   A n a l y t i c s   S h o r t   C u t   -   h t t p : / / g a s h o r t c u t . c o m /  
 / / / / / / /  
  
 / * *  
   *   @ f i l e o v e r v i e w   W r a p p e r   f o r   g a A d d o n s  
   * /  
 v a r   b U s e E v e n t F o r O u t b o u n d   =   t r u e ;   / /   S e t   t o   f a l s e   t o   u s e   t r a c k P a g e v i e w   f o r   o u t b o u n t   l i n k s  
 v a r   b U s e E v e n t F o r D o w n l o a d   =   t r u e ;   / /   S e t   t o   f a l s e   t o   u s e   t r a c k P a g e v i e w   f o r   d o w n l o a d s  
 v a r   g a A _ f i l e T y p e s   =   n e w   R e g E x p ( / \ . ( d o c x * | x l s x * | p p t x * | e x e | z i p | p d f | x p i ) $ / i ) ;  
 / /   I n d i c a t e   e a c h   f i l e   e x t e n s i o n   t h a t   n e e d s   t o   b e   t r a c k e d ,   g a A _ f i l e T y p e s   i s   t h e   r e g u l a r   e x p r e s s i o n   t h a t   m a t c h e s   d o w n l o a d a b l e   f i l e s  
 v a r   g a A _ p a g e T r a c k e r   =   p a g e T r a c k e r ;   / /   S h o u l d   b e   s e t   t o   t h e   n a m e   o f   y o u r   t r a c k e r   v a r i a b l e  
  
 / / / / / / /  
 / / /   N o   n e e d   t o   c h a n g e   a n y t h i n g   b e l o w   t h i s   l i n e  
 / * *  
   *   @ c l a s s   g a   A d d o n s   c o m p o n e n t .  
   *           T h i s   c l a s s   e n c a p s u l a t e s   a l l   l o g i c   f o r   t h e   G o o g l e   A n a l y t i c s   a d d o n s  
   *   @ c o n s t r u c t o r  
   * /  
 v a r   g a A d d o n s   =   f u n c t i o n ( ) {  
         / * *  
           *   s t a r t L i s t e n i n g :   a d d   a   n e w   l i s t n e r   f o r   o n c l i c k   e v e n t ,   h a n d l e   M o z i l l a   o r   I E   m e t h o d s  
           *   @ p a r a m   { O b j e c t }   o b j   H R E F   o b j e c t   t o   l i s t e n   t o  
           *   @ p a r a m   { S t r i n g }   e v n t   e v e n t   t y p e   ( u s u a l l y   " c l i c k " )  
           *   @ p a r a m   { O b j e c t }   f u n c   F u n c t i o n   t o   c a l l   w h e n   e v n t   i s   t r i g g e r e d  
           * /  
         v a r   s t a r t L i s t e n i n g   =   f u n c t i o n ( o b j ,   e v n t ,   f u n c ) {  
                 i f   ( o b j . a d d E v e n t L i s t e n e r )    
                         o b j . a d d E v e n t L i s t e n e r ( e v n t ,   f u n c ,   f a l s e ) ;  
                 e l s e    
                         i f   ( o b j . a t t a c h E v e n t )    
                                 o b j . a t t a c h E v e n t ( " o n "   +   e v n t ,   f u n c ) ;  
         }  
          
         / * *  
           *   t r a c k D o c u m e n t :   m a k e   G A   c a l l   w h e n   d o w n l o a d i n g   o n e   o f   d e t e c t e d   f i l e   e x t e n s i o n ,   u s e   t r a c k E v e n t ( )   o r   t r a c k P a g e V i e w ( )   m e t h o d s  
           *   @ p a r a m   { O b j e c t }   e v n t   O b j e c t   w h e r e   t h e   e v e n t   h a p p e n e d  
           * /  
         v a r   t r a c k D o c u m e n t   =   f u n c t i o n ( e v n t ) {  
                 b U s e E v e n t F o r D o w n l o a d   ?   g a A _ p a g e T r a c k e r . _ t r a c k E v e n t ( " d o w n l o a d " ,   " c l i c k " ,   ( e v n t . s r c E l e m e n t )   ?   " / "   +   e v n t . s r c E l e m e n t . p a t h n a m e   :   t h i s . p a t h n a m e )   :   g a A _ p a g e T r a c k e r . _ t r a c k P a g e v i e w ( " / d o w n l o a d / "   +   ( e v n t . s r c E l e m e n t )   ?   " / "   +   e v n t . s r c E l e m e n t . p a t h n a m e   :   t h i s . p a t h n a m e ) ;  
         }  
          
         / * *  
           *   t r a c k E x t e r n a l L i n k :   m a k e   G A   c a l l   w h e n   c l i c k i n g   a n   o u t b o u n d   l i n k ,   u s e   t r a c k E v e n t ( )   o r   t r a c k P a g e V i e w ( )   m e t h o d s  
           *   @ p a r a m   { O b j e c t }   e v n t   O b j e c t   w h e r e   t h e   e v e n t   h a p p e n e d  
           * /  
         v a r   t r a c k E x t e r n a l L i n k   =   f u n c t i o n ( e v n t ) {  
                 v a r   e l m n t   =   e v n t . s r c E l e m e n t ;  
                 i f   ( e l m n t )   {  
                         w h i l e   ( e l m n t . t a g N a m e   ! =   " A " )    
                                 e l m n t   =   e l m n t . p a r e n t N o d e ;  
                         i f   ( / h t t p / . t e s t ( e l m n t . p r o t o c o l ) )    
                                 b U s e E v e n t F o r O u t b o u n d   ?   g a A _ p a g e T r a c k e r . _ t r a c k E v e n t ( " o u t b o u n d " ,   " c l i c k " ,   e l m n t . h o s t n a m e   +   " / "   +   e l m n t . p a t h n a m e   +   e l m n t . s e a r c h )   :   g a A _ p a g e T r a c k e r . _ t r a c k P a g e v i e w ( " / o u t b o u n d / "   +   e l m n t . h o s t n a m e   +   " / "   +   e l m n t . p a t h n a m e   +   e l m n t . s e a r c h ) ;  
                         i f   ( e l m n t . p r o t o c o l   = =   " m a i l t o : " )    
                                 b U s e E v e n t F o r O u t b o u n d   ?   g a A _ p a g e T r a c k e r . _ t r a c k E v e n t ( " m a i l t o " ,   " c l i c k " ,   e l m n t . h r e f . r e p l a c e ( / m a i l t o : / ,   " " ) )   :   g a A _ p a g e T r a c k e r . _ t r a c k P a g e v i e w ( " / m a i l t o / "   +   e l m n t . h r e f . r e p l a c e ( / m a i l t o : / ) ) ;  
                 }  
                 e l s e   {  
                         i f   ( / h t t p / . t e s t ( t h i s . p r o t o c o l ) )    
                                 b U s e E v e n t F o r O u t b o u n d   ?   g a A _ p a g e T r a c k e r . _ t r a c k E v e n t ( " o u t b o u n d " ,   " c l i c k " ,   t h i s . h o s t n a m e   +   t h i s . p a t h n a m e   +   t h i s . s e a r c h )   :   g a A _ p a g e T r a c k e r . _ t r a c k P a g e v i e w ( " / o u t b o u n d / "   +   t h i s . h o s t n a m e   +   t h i s . p a t h n a m e   +   t h i s . s e a r c h ) ;  
                         i f   ( t h i s . p r o t o c o l   = =   " m a i l t o : " )    
                                 b U s e E v e n t F o r O u t b o u n d   ?   g a A _ p a g e T r a c k e r . _ t r a c k E v e n t ( " m a i l t o " ,   " c l i c k " ,   t h i s . h r e f . r e p l a c e ( / m a i l t o : / ,   " " ) )   :   g a A _ p a g e T r a c k e r . _ t r a c k P a g e v i e w ( " / m a i l t o / "   +   t h i s . h r e f . r e p l a c e ( / m a i l t o : / ) ) ;  
                 }  
         }  
  
         / * *  
           *   I n i t i a l i z e   g a A d d o n s  
           * /  
         i f   ( d o c u m e n t . g e t E l e m e n t s B y T a g N a m e   & &   t y p e o f   g a A _ p a g e T r a c k e r   = =   " o b j e c t " )   {  
                 v a r   h r e f s   =   d o c u m e n t . g e t E l e m e n t s B y T a g N a m e ( ' a ' ) ;  
                 f o r   ( v a r   l   =   0 ,   m   =   h r e f s . l e n g t h ;   l   <   m ;   l + + )    
                         i f   ( g a A _ f i l e T y p e s . t e s t ( h r e f s [ l ] . p a t h n a m e ) )    
                                 s t a r t L i s t e n i n g ( h r e f s [ l ] ,   " c l i c k " ,   t r a c k D o c u m e n t ) ;  
                         e l s e    
                                 i f   ( h r e f s [ l ] . h o s t n a m e   ! =   l o c a t i o n . h o s t n a m e )    
                                         s t a r t L i s t e n i n g ( h r e f s [ l ] ,   " c l i c k " ,   t r a c k E x t e r n a l L i n k ) ;  
         }  
 }  
  
 i f   ( w i n d o w . a d d E v e n t L i s t e n e r )   / /   S t a n d a r d  
         w i n d o w . a d d E v e n t L i s t e n e r ( ' l o a d ' ,   f u n c t i o n ( ) {  
                 g a A d d o n s ( )  
         } ,   f a l s e ) ;  
 e l s e    
         i f   ( w i n d o w . a t t a c h E v e n t )   / /   I E  
                 w i n d o w . a t t a c h E v e n t ( ' o n l o a d ' ,   f u n c t i o n ( ) {  
                         g a A d d o n s ( )  
                 } ) ;  
 / / /   E O F   / / /  
 
