0.0.3 • Published 8 years ago
ember-google-optimize v0.0.3
ember-google-optimize
A very quick and dirty addon to include Google Optimize into an Ember app.
Notes
- Expects there to be a global
gavariable it can use to require the optimize lib - Google Optimize doesn't seem to load the previews / redirects on localhost.
- The activation event name is
optimize.activate
Installation
ember install ember-google-optimize
Usage
Use the provided optimize service to amend your app/router.js file to trigger page load activations. This will use the dataLayer to send the event optimize.activate.
...
const Router = EmberRouter.extend(GooglePageview, RouterScroll, {
...
optimize: service(),
didTransition() {
this._super(...arguments);
this._activateOptimize();
},
_activateOptimize() {
scheduleOnce("afterRender", this, () => {
get(this, "optimize").activate();
});
},
...
});Configuration
This plugin uses the Ember CLI project's configuration as defined in config/environment.js.
The tracking code will appear only if ENV.googleOptimize.container is defined. For instance, to enable the tracking code in only the production environment:
if (environment === "production") {
ENV.googleOptimize = {
container: "GTM-XXXXXX"
};
}Configuration Parameters
container(Default:null): the container ID for the Google Optimize container.injectFlickerSnippet(Default:true): Inject the Google Optimize flicker prevention script into the index.html<head>
Running
ember serve- Visit your app at http://localhost:4200.
Running Tests
npm test(Runsember try:eachto test your addon against multiple Ember versions)ember testember test --server
Building
ember build
For more information on using ember-cli, visit https://ember-cli.com/.