-
-
Save Tftlegal/dcb8d782e1c4a283a9eaa19229021a21 to your computer and use it in GitHub Desktop.
Add Google Analytics tracking code to HTML via nginx
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
| # | |
| # Add Google Analytics tracking code to HTML response | |
| # | |
| # Usage: | |
| # set $tracking_id 'G-GEJQX7TP2Z'; | |
| # include snippets/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