Skip to content

Commit

Permalink
Merge pull request #16 from tsteuwer/enable-fastboot
Browse files Browse the repository at this point in the history
FastBoot Fixes
  • Loading branch information
tsteuwer authored Aug 8, 2017
2 parents d91c07c + b328e7b commit 2b2c86e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The simple way of tracking your app or addon using:
[Tealium IQ](http://tealium.com/products/tealium-iq-tag-management-system/) tag manager
- [x] Support for dev, qa and production environments out-of-the-box.

*FastBoot Ready!*

For more information about this addon, please visit the [Ember Tracker website][main-site-url].

## Minimum Requirements
Expand Down
16 changes: 16 additions & 0 deletions addon/-privates/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*global window document*/

import Ember from 'ember';

/**
Expand All @@ -16,3 +18,17 @@ export function getCurrentRoute(context, routeName) {
* @type {Function}
*/
export const mergeObjects = Ember.assign || Ember.merge;

/**
* Find out if we're in fastboot.
* @public
* @type {Boolean}
*/
export const IN_BROWSER = !!window && !!window.document;

/**
* Merge or assign.
* @public
* @type {Function}
*/
export const mergeOrAssign = Ember.assign || Ember.merge;
3 changes: 2 additions & 1 deletion addon/mixins/google-analytics-route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from 'ember';
import { getCurrentRoute } from 'ember-tracker/-privates/utils';
import { IN_BROWSER } from 'ember-tracker/-privates/utils';

const {
inject: {
Expand Down Expand Up @@ -70,5 +71,5 @@ export default Ember.Mixin.create({
* @return {String}
*/
function getTitle(route) {
return route.get('title') || (document && document.title) || '';
return route.get('title') || (IN_BROWSER && document && document.title) || '';
}
3 changes: 2 additions & 1 deletion addon/mixins/tealium-route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from 'ember';
import { getCurrentRoute, mergeObjects } from 'ember-tracker/-privates/utils';
import { IN_BROWSER } from 'ember-tracker/-privates/utils';

const {
getWithDefault,
Expand Down Expand Up @@ -34,7 +35,7 @@ export default Ember.Mixin.create({

this._super(...arguments);

if (!testing) {
if (!testing && IN_BROWSER) {
this._etCheckForUtag();
}
},
Expand Down
6 changes: 4 additions & 2 deletions addon/services/google-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/*eslint no-unused-vars: 0 */
import Ember from 'ember';

import { IN_BROWSER, mergeOrAssign } from 'ember-tracker/-privates/utils';

const {
assert,
computed: {
Expand Down Expand Up @@ -88,7 +90,7 @@ export default Ember.Service.extend({
_logAnalyticsEvents: get(config, 'emberTracker.analyticsSettings.LOG_EVENTS'),
});

if (!testing) {
if (!testing && IN_BROWSER) {
this._etCheckForGA();
}
},
Expand Down Expand Up @@ -249,7 +251,7 @@ export default Ember.Service.extend({

if (ga) {
ga('set', 'page', page);
ga('send', 'pageview', Ember.assign({
ga('send', 'pageview', mergeOrAssign({
page,
title,
}, options || {}));
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-cli": "2.12.1",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "^3.0.0",
Expand All @@ -38,14 +37,14 @@
"ember-cli-qunit": "^3.1.0",
"ember-cli-release": "^0.2.9",
"ember-cli-shims": "^1.0.2",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.6.0",
"ember-resolver": "^2.0.3",
"ember-source": "~2.12.0",
"loader.js": "^4.2.3"
"loader.js": "^4.2.3",
"phantomjs-prebuilt": "^2.1.14"
},
"engines": {
"node": ">= 4"
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/-privates/routes/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import { IN_BROWSER } from 'ember-tracker/-privates/utils';

const {
on,
Expand All @@ -25,7 +26,7 @@ export default Ember.Route.extend({
* @return {undefined}
*/
function _updateMetaInfo() {
if (testing) {
if (testing || !IN_BROWSER) {
return;
}

Expand Down
19 changes: 18 additions & 1 deletion tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<p>
<code>ember-tracker</code> is a simple <a href="https://emberjs.com">Ember</a> addon which easily implements popular tracking software such as {{#link-to "google-analytics"}}Google Analytics{{/link-to}} and {{#link-to "tealium"}}Tealium IQ{{/link-to}}.
<code>ember-tracker</code> is a simple <a href="https://emberjs.com">Ember</a> addon which easily implements popular tracking software such as {{#link-to "google-analytics"}}Google Analytics{{/link-to}} and {{#link-to "tealium"}}Tealium IQ{{/link-to}}.<br/>
<p>
Out of the box you'll get:
<h5><strong>Google Analytics</strong></h5>
<ul>
<li>Pageviews - Every transition will be captured and sent as a page view!</li>
<li>Events - Track what your users are doing by using the `events` events API.</li>
<li>User Timing - Gague performance with the `timing` API.</li>
<li>Social - Track shares, tweets, etc with the `social` (network) API.</li>
<li>Custom page/titles and "before analytics" callback.</li>
</ul>
<h5><strong>Tealium</strong></h5>
<ul>
<li>Support for dev, qa and production environments..</li>
</ul>
</p>
</p>
<h4>Installation</h4>
<p>Install the addon simply by using the following command.</p>
Expand All @@ -10,3 +25,5 @@
<li>Learn how to setup and start tracking pageview's or sending events with {{#link-to "google-analytics"}}Google Analytics{{/link-to}}.</li>
<li>Or, learn how to setup {{#link-to "tealium"}}Tealium IQ{{/link-to}}.</li>
</ul>
<h4>FastBoot Ready</h4>
<p>Ember Tracker is now <a href="https://ember-fastboot.com" rel="nofollow">FastBoot</a> ready!</p>
2 changes: 2 additions & 0 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = function(environment) {
},
emberTracker: {
analyticsSettings: {
LOG_PAGEVIEW: true,
LOG_EVENTS: true,
trackingId: 'UA-97028033-2',
onload: false,
afterCreate: 'console.log("test after create");'
Expand Down

0 comments on commit 2b2c86e

Please sign in to comment.