From d96fb39f39b353baf159136c4802db12f4b63baa Mon Sep 17 00:00:00 2001 From: Troy Steuwer Date: Mon, 7 Aug 2017 18:36:26 -0400 Subject: [PATCH 1/3] Disable dom manipulation for fastboot by checking if FastBoot is undefined --- addon/-privates/utils.js | 7 +++++++ addon/mixins/google-analytics-route.js | 3 ++- addon/mixins/tealium-route.js | 3 ++- addon/services/google-analytics.js | 4 +++- tests/dummy/app/-privates/routes/base.js | 3 ++- tests/dummy/config/environment.js | 2 ++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addon/-privates/utils.js b/addon/-privates/utils.js index 7fbba8d..7685684 100644 --- a/addon/-privates/utils.js +++ b/addon/-privates/utils.js @@ -16,3 +16,10 @@ 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 = typeof FastBoot === 'undefined'; diff --git a/addon/mixins/google-analytics-route.js b/addon/mixins/google-analytics-route.js index 9d7bb4b..494ee2a 100644 --- a/addon/mixins/google-analytics-route.js +++ b/addon/mixins/google-analytics-route.js @@ -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: { @@ -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) || ''; } diff --git a/addon/mixins/tealium-route.js b/addon/mixins/tealium-route.js index adbbeae..70af9ff 100644 --- a/addon/mixins/tealium-route.js +++ b/addon/mixins/tealium-route.js @@ -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, @@ -34,7 +35,7 @@ export default Ember.Mixin.create({ this._super(...arguments); - if (!testing) { + if (!testing && IN_BROWSER) { this._etCheckForUtag(); } }, diff --git a/addon/services/google-analytics.js b/addon/services/google-analytics.js index bbb4136..a488612 100644 --- a/addon/services/google-analytics.js +++ b/addon/services/google-analytics.js @@ -2,6 +2,8 @@ /*eslint no-unused-vars: 0 */ import Ember from 'ember'; +import { IN_BROWSER } from 'ember-tracker/-privates/utils'; + const { assert, computed: { @@ -88,7 +90,7 @@ export default Ember.Service.extend({ _logAnalyticsEvents: get(config, 'emberTracker.analyticsSettings.LOG_EVENTS'), }); - if (!testing) { + if (!testing && IN_BROWSER) { this._etCheckForGA(); } }, diff --git a/tests/dummy/app/-privates/routes/base.js b/tests/dummy/app/-privates/routes/base.js index 4364487..e3cebfe 100644 --- a/tests/dummy/app/-privates/routes/base.js +++ b/tests/dummy/app/-privates/routes/base.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { IN_BROWSER } from 'ember-tracker/-privates/utils'; const { on, @@ -25,7 +26,7 @@ export default Ember.Route.extend({ * @return {undefined} */ function _updateMetaInfo() { - if (testing) { + if (testing || !IN_BROWSER) { return; } diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 1beb044..5a27695 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -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");' From 2b2f0619aac6257540d0e8c2f6057f7a94604365 Mon Sep 17 00:00:00 2001 From: Troy Steuwer Date: Tue, 8 Aug 2017 08:36:10 -0400 Subject: [PATCH 2/3] updating a couple of things and fixing an issue with 2.4 --- README.md | 2 ++ addon/-privates/utils.js | 11 ++++++++++- addon/services/google-analytics.js | 4 ++-- package.json | 3 ++- tests/dummy/app/templates/index.hbs | 19 ++++++++++++++++++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6a9b332..3ed4a16 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/addon/-privates/utils.js b/addon/-privates/utils.js index 7685684..6dd701a 100644 --- a/addon/-privates/utils.js +++ b/addon/-privates/utils.js @@ -1,3 +1,5 @@ +/*global window document*/ + import Ember from 'ember'; /** @@ -22,4 +24,11 @@ export const mergeObjects = Ember.assign || Ember.merge; * @public * @type {Boolean} */ -export const IN_BROWSER = typeof FastBoot === 'undefined'; +export const IN_BROWSER = !!window && !!window.document; + +/** + * Merge or assign. + * @public + * @type {Function} + */ +export const mergeOrAssign = Ember.assign || Ember.merge; diff --git a/addon/services/google-analytics.js b/addon/services/google-analytics.js index a488612..b657ee8 100644 --- a/addon/services/google-analytics.js +++ b/addon/services/google-analytics.js @@ -2,7 +2,7 @@ /*eslint no-unused-vars: 0 */ import Ember from 'ember'; -import { IN_BROWSER } from 'ember-tracker/-privates/utils'; +import { IN_BROWSER, mergeOrAssign } from 'ember-tracker/-privates/utils'; const { assert, @@ -251,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 || {})); diff --git a/package.json b/package.json index f9f97df..39d6653 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "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" diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 0849994..81c515e 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1,5 +1,20 @@

-ember-tracker is a simple Ember 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}}. + ember-tracker is a simple Ember 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}}.
+

+ Out of the box you'll get: +

Google Analytics
+ +
Tealium
+ +

Installation

Install the addon simply by using the following command.

@@ -10,3 +25,5 @@
  • Learn how to setup and start tracking pageview's or sending events with {{#link-to "google-analytics"}}Google Analytics{{/link-to}}.
  • Or, learn how to setup {{#link-to "tealium"}}Tealium IQ{{/link-to}}.
  • +

    FastBoot Ready

    +

    Ember Tracker is now FastBoot ready!

    From b328e7be214d0904949366f9486f9b9416d46525 Mon Sep 17 00:00:00 2001 From: Troy Steuwer Date: Tue, 8 Aug 2017 08:43:08 -0400 Subject: [PATCH 3/3] Removing uneeded dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 39d6653..daf46b9 100644 --- a/package.json +++ b/package.json @@ -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", @@ -38,7 +37,6 @@ "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",