David Chambers avatar David Chambers committed 5b0cedd

Cakefile: add `--ga-key` option for setting the Google Analytics key

Comments (0)

Files changed (4)

 files = [
-  'ga.js'
+option null, '--ga-key [KEY]',  'set the Google Analytics key'
 option '-o', '--output [FILE]', 'write output to <file> instead of stdout'
 task 'build:scripts', 'concatenate and minify JavaScript files', (options) ->
     if /[.]coffee$/.test filename then CoffeeScript.compile data else data
   {ast_mangle, ast_squeeze, gen_code} = uglify
-  data = (read f for f in files).join(';')
-  data = gen_code ast_squeeze ast_mangle parser.parse data
+  scripts = (read f for f in files)
+  if key = options['ga-key']
+    scripts.push read('src/ga.coffee').replace /<KEY>/g, key
+  data = gen_code ast_squeeze ast_mangle parser.parse scripts.join ';'
   if options.output? then fs.writeFileSync options.output, data, 'utf8'
   else console.log data
 ### Deploying Hashify
     hg pull --update
-    cake --output ./concat.min.js build:scripts
+    cake --ga-key UA-22176121-1 --output ./concat.min.js build:scripts


-var _gaq = [
-  ['_setAccount', 'UA-22176121-1'],
-  ['_trackPageview']
-(function (ga, s) {
-  ga = document.createElement('script');
-  ga.async = true;
-  ga.type = 'text/javascript';
-  ga.src = 'http://www.google-analytics.com/ga.js';
-  s = document.getElementsByTagName('script')[0];
-  s.parentNode.insertBefore(ga, s);
+window._gaq = [
+  ['_setAccount', '<KEY>']
+  ['_trackPageview']
+script = document.createElement 'script'
+script.async = true
+script.type = 'text/javascript'
+script.src = 'http://www.google-analytics.com/ga.js'
+document.body.insertBefore script, document.getElementById 'script'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.