Created
          October 24, 2011 23:02 
        
      - 
      
- 
        Save ungoldman/1310638 to your computer and use it in GitHub Desktop. 
    ga click tracking w/ data attributes
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!DOCTYPE HTML> | |
| <html lang='en-US'> | |
| <head> | |
| <meta charset='UTF-8'> | |
| <title></title> | |
| </head> | |
| <body> | |
| <a data-ga='play' data-context='game'>Play</a> | |
| <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> | |
| <script> | |
| var _gaq = [['_setAccount','UA-XXXXX-X'], ['_trackPageview']]; | |
| (function(d, t) { | |
| var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; | |
| g.async = true; g.src = ('https:' == document.location.protocol ? | |
| 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
| s.parentNode.insertBefore(g, s); | |
| })(document, 'script'); | |
| $(function(){ | |
| $(document).on('click','[data-ga]',function(){ | |
| var g = $(this).data('ga'), c = $(this).data('context'); | |
| typeof _gaq != 'undefined' && _gaq.push(['_trackEvent',g,'click',c]); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
NEVER DO THIS
EVER