-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Grippi
committed
Oct 18, 2014
1 parent
e23a304
commit 2e227fa
Showing
42 changed files
with
131 additions
and
465 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# compiled output | ||
/dist | ||
/tmp | ||
|
||
# dependencies | ||
/node_modules | ||
/bower_components | ||
|
||
# misc | ||
/.sass-cache | ||
/connect.lock | ||
/coverage/* | ||
/libpeerconnection.log | ||
npm-debug.log | ||
testem.log |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ember-cli-google-analytics Changelog | ||
|
||
### 1.0.0 | ||
|
||
Initial release of the ember-cli-google-analytics addon |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Peter Grippi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
# Ember-cli-google-analytics | ||
# ember-cli-google-analytics | ||
|
||
This README outlines the details of collaborating on this Ember addon. | ||
Plugin for ember-cli that injects Google Analytics tracking code into HTML content. | ||
|
||
## Installation | ||
|
||
* `git clone` this repository | ||
* `npm install` | ||
* `bower install` | ||
**This plugin requires ember-cli version >= 0.0.47** | ||
|
||
## Running | ||
To install simply run: | ||
|
||
* `ember server` | ||
* Visit your app at http://localhost:4200. | ||
``` | ||
npm install --save-dev ember-cli-google-analytics | ||
``` | ||
|
||
## Running Tests | ||
## Warning: Content Security Policy | ||
|
||
* `ember test` | ||
* `ember test --server` | ||
This plugin is intended to add Google Analytics tracking as an inline script. The [ember-cli-content-security-policy](https://github.com/rwjblue/ember-cli-content-security-policy) addon that is included with ember-cli will prevent the execution of inline scripts. | ||
|
||
## Building | ||
A future version of this plugin is planned to add the tracking code as an additional JS file (much like [ember-cli-inject-live-reload](https://github.com/rwjblue/ember-cli-inject-live-reload)), but until then this plugin will not function out of the box with CSP installed. | ||
|
||
* `ember build` | ||
## Configuration | ||
|
||
For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/). | ||
This plugin uses the Ember CLI project's configuration as defined in `config/environment.js`. | ||
|
||
The tracking code will appear only if `ENV.googleAnalytics.webPropertyId` is defined. For instance, to enable the tracking code in only the production environment: | ||
|
||
```javascript | ||
if (environment === 'production') { | ||
ENV.googleAnalytics = { | ||
webPropertyId: 'UA-XXXX-Y' | ||
}; | ||
} | ||
``` | ||
|
||
### Configuration Parameters | ||
|
||
* `webPropertyId` (Default: `null`): the Web Property ID for the Google Web Property you wish to track. | ||
* `tracker` (Default: `analytics.js`): The Google Tracker to use, can be either `analytics.js` or `ga.js` | ||
* `globalVariable` (Default: `ga`): the global variable to use for the Google Analytics tracker object. This is ignored when the `tracker` is `ga.js`. |
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
'use strict'; | ||
|
||
var merge = require('lodash-node/compat/objects/merge'); | ||
var googleAnalyticsConfigDefaults = { | ||
globalVariable: 'ga', | ||
tracker: 'analytics.js', | ||
webPropertyId: null | ||
}; | ||
|
||
function analyticsTrackingCode(config) { | ||
return [ | ||
"<script>", | ||
"(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){", | ||
"(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),", | ||
"m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)", | ||
"})(window,document,'script','//www.google-analytics.com/analytics.js','" + config.globalVariable + "');", | ||
"", | ||
"" + config.globalVariable + "('create', '" + config.webPropertyId + "', 'auto');", | ||
"" + config.globalVariable + "('send', 'pageview');", | ||
"</script>" | ||
]; | ||
} | ||
|
||
function gaTrackingCode(config) { | ||
return [ | ||
"<script>", | ||
"var _gaq = _gaq || [];", | ||
"_gaq.push(['_setAccount', '" + config.webPropertyId + "']);", | ||
"_gaq.push(['_trackPageview']);", | ||
"", | ||
"(function() {", | ||
" var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;", | ||
" ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';", | ||
" var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);", | ||
"})();", | ||
"</script>" | ||
]; | ||
} | ||
|
||
module.exports = { | ||
name: 'ember-cli-google-analytics' | ||
name: 'ember-cli-google-analytics', | ||
contentFor: function(type, config) { | ||
var googleAnalyticsConfig = merge({}, googleAnalyticsConfigDefaults, config.googleAnalytics || {}); | ||
|
||
if (type === 'head' && googleAnalyticsConfig.webPropertyId != null) { | ||
var content; | ||
|
||
if (googleAnalyticsConfig.tracker === 'analytics.js') { | ||
content = analyticsTrackingCode(googleAnalyticsConfig); | ||
} else if (googleAnalyticsConfig.tracker === 'ga.js') { | ||
content = gaTrackingCode(googleAnalyticsConfig); | ||
} else { | ||
throw new Error('Invalid tracker found in configuration: "' + googleAnalyticsConfig.tracker + '". Must be one of: "analytics.js", "ga.js"'); | ||
} | ||
|
||
return content.join("\n"); | ||
} | ||
|
||
return ''; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
{ | ||
"name": "ember-cli-google-analytics", | ||
"version": "0.0.0", | ||
"directories": { | ||
"doc": "doc", | ||
"test": "tests" | ||
}, | ||
"version": "1.0.0", | ||
"scripts": { | ||
"start": "ember server", | ||
"build": "ember build", | ||
"test": "ember test" | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/pgrippi/ember-cli-google-analytics.git" | ||
}, | ||
"repository": "https://github.com/stefanpenner/ember-cli", | ||
"bugs": { | ||
"url": "https://github.com/pgrippi/ember-cli-google-analytics/issues" | ||
}, | ||
"homepage": "https://github.com/pgrippi/ember-cli-google-analytics", | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"author": "", | ||
"author": "Peter Grippi", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"body-parser": "^1.2.0", | ||
"broccoli-asset-rev": "0.3.1", | ||
"broccoli-ember-hbs-template-compiler": "^1.6.1", | ||
"ember-cli": "0.1.2", | ||
"ember-cli-content-security-policy": "0.3.0", | ||
"ember-export-application-global": "^1.0.0", | ||
"ember-cli-ic-ajax": "0.1.1", | ||
"ember-cli-inject-live-reload": "^1.3.0", | ||
"ember-cli-qunit": "0.1.0", | ||
"ember-data": "1.0.0-beta.10", | ||
"express": "^4.8.5", | ||
"glob": "^4.0.5" | ||
}, | ||
"devDependencies": {}, | ||
"keywords": [ | ||
"ember-addon" | ||
"ember-addon", | ||
"ember-cli", | ||
"google", | ||
"analytics" | ||
], | ||
"ember-addon": { | ||
"configPath": "tests/dummy/config" | ||
"ember-addon": {}, | ||
"dependencies": { | ||
"lodash-node": "^2.4.1" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.