-
-
Save akhy/48d45ec67e1c1fc5bc2fdd5b98028ab8 to your computer and use it in GitHub Desktop.
Add Google Analytics tracking code to HTML via nginx
This file contains 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
# | |
# Add Google Analytics tracking code to HTML response | |
# | |
# Usage: | |
# set $tracking_id 'UA-12345678-9'; | |
# include incl/analytics.conf; | |
# | |
# It needs nginx compiled with option --with-http_sub_module. | |
# Uses optimized GA code from: http://mathiasbynens.be/notes/async-analytics-snippet | |
# | |
sub_filter '</head>' '<script type="text/javascript">var _gaq=[["_setAccount","$tracking_id"],["_trackPageview"]];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;g.src="//www.google-analytics.com/ga.js";s.parentNode.insertBefore(g,s)})(document,"script")</script></head>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment