All Projects → willviles → ember-google-analytics-embed

willviles / ember-google-analytics-embed

Licence: MIT license
An Ember Addon for adding analytics visualizations using the Google Analytics Embed API.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ember-google-analytics-embed

ember-google-charts
Google's Material charts made easy for Ember apps - http://sir-dunxalot.github.io/ember-google-charts/
Stars: ✭ 31 (+19.23%)
Mutual labels:  ember, ember-addon, google-charts
ember-foxy-forms
Ember Addon for Making Foxy Forms
Stars: ✭ 27 (+3.85%)
Mutual labels:  ember, ember-addon
ember-best-language
🏳 A FastBoot-enabled addon to detect the best language for your user.
Stars: ✭ 18 (-30.77%)
Mutual labels:  ember, ember-addon
ember-event-helpers
Complimentary event template helpers to the {{on}} modifier
Stars: ✭ 33 (+26.92%)
Mutual labels:  ember, ember-addon
ember-cli-g-maps
Deprecated Google Maps Addon
Stars: ✭ 58 (+123.08%)
Mutual labels:  ember, ember-addon
ember-fastboot-app-tests
FastBoot testing support for Ember apps
Stars: ✭ 17 (-34.62%)
Mutual labels:  ember, ember-addon
ember-cordova
CLI for Ember/Cordova/Crosswalk Applications
Stars: ✭ 16 (-38.46%)
Mutual labels:  ember, ember-addon
ember-lazy-responsive-image
Generate and render responsive, lazy loaded, LQIP enabled images
Stars: ✭ 14 (-46.15%)
Mutual labels:  ember, ember-addon
ember-useragent
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
Stars: ✭ 34 (+30.77%)
Mutual labels:  ember, ember-addon
ember-ref-bucket
This is list of handy ember primitives, created to simplify class-based dom workflow
Stars: ✭ 31 (+19.23%)
Mutual labels:  ember, ember-addon
ember-query-params
Ember service for your query params
Stars: ✭ 44 (+69.23%)
Mutual labels:  ember, ember-addon
ember-content-loader
Easy, customizable content placeholders / skeletons screens
Stars: ✭ 41 (+57.69%)
Mutual labels:  ember, ember-addon
ember-on-modifier
Implements the `{{on eventName this.someAction}}` element modifier from https://github.com/emberjs/rfcs/blob/master/text/0471-on-modifier.md
Stars: ✭ 37 (+42.31%)
Mutual labels:  ember, ember-addon
ember-get-config
Get `config/environment` from anywhere, even addons!!!
Stars: ✭ 63 (+142.31%)
Mutual labels:  ember, ember-addon
ember-responsive-image
Automatically generate resized images at build-time, optimized for the responsive web, and using components to render them easily as <picture> elements.
Stars: ✭ 103 (+296.15%)
Mutual labels:  ember, ember-addon
ember-link
Link primitive to pass around self-contained route references. It's {{link-to}}, but better!
Stars: ✭ 50 (+92.31%)
Mutual labels:  ember, ember-addon
ember-named-yields
Named Yields for Ember Components
Stars: ✭ 17 (-34.62%)
Mutual labels:  ember, ember-addon
pagination-pager
Ember.js Component for Bootstrap 3 pagination & pager components
Stars: ✭ 56 (+115.38%)
Mutual labels:  ember, ember-addon
ember-cli-concat
An Ember addon that enables you to concatinate Ember CLI's app and vendor files into a single JS file and a single CSS file
Stars: ✭ 31 (+19.23%)
Mutual labels:  ember, ember-addon
ember-cli-yadda
Write cucumber specs for ember-cli applications
Stars: ✭ 41 (+57.69%)
Mutual labels:  ember, ember-addon

Ember Google Analytics Embed

Build Status Ember Observer Score Download count all time npm

Ember Google Analytics Embed is an addon for quickly building custom Google Analytics dashboards in your Ember.js app, using the Google Analytics Embed API.

The addon exposes the following components to use in your templates:

The addon also enables Analytics user authorization using the authorization (ga-embed-authorize) component and view selection via the view selector (ga-embed-view-selector) component.

Demos

Check out the Embed API demos page for examples.

Installation

ember install ember-google-analytics-embed

Setup

To authorize your application to access the Google Analytics API, you must create a Client ID from the Google API Console. When you've obtained your Client ID, add it to your environment file. If you are using Geo Charts, you must also include an API Key, for accessing the Google Maps Javascript API. Both these APIs must be enabled from your API console and have the right origins/referrers set.

// config/environment.js
ENV['google-analytics-embed'] = {
  clientId: 'YOUR_CLIENT_ID',
  apiKey: 'YOUR_API_KEY'
};

Authorization

There are two ways to authorize users: through the authorization flow, requiring a user to click and authenticate, or via an access token sent from your server.

Adding the base ga-embed-authorize component to your templates will create a 'Sign in to Google Analytics' button and handle the authorization flow automatically:

{{ga-embed-authorize}}

Inject the ga-embed service into your templates to conditionally show/hide elements:

{{#if gaEmbed.isAuthorized}}
  // Add visualizations here
{{/if}}

The ga-embed service also exposes information about the current authorized user:

{{log gaEmbed.authorizedUser}}
// => { email: '[email protected]', imageUrl: '...', name: 'Foo Bar' }

Sign Out

To enable the user to sign out, inject the ga-embed service into the consuming object and create the following action.

gaEmbed: service(),

actions: {
  signOut() {
    get(this, 'gaEmbed').signOut().then(() => {
      // Returns a promise when complete
    });
  }
}

Access Token Authorization

To remove the user auth flow, you may return an access token from your server. Simply pass the access token to the ga-embed-authorize component. You can find more information on setting up server side authorization here.

{{ga-embed-authorize accessToken=analyticsAccessToken}}

Visualizations

Each visualization accepts two main attributes, a query and an options hash.

Query

To get data from our Google Analytics property, we must build a query using the Google Reporting API. The example below shows a pie chart of sessions, segmented by country. It limits the data to the last 30 days up until today and requests just the top ten results.

{{ga-embed-pie-chart
    query=(hash
      ids="YOUR_PROPERTY_ID"
      metrics="ga:sessions"
      dimensions="ga:country"
      start-date="30daysAgo"
      sort="-ga:sessions"
      max-results=10
      end-date="today"
    )}}

Options

An options hash may be passed to each chart, allowing full configuration of the visualization.

{{ga-embed-pie-chart query=query options=options}}

Individual options properties may also be passed and can be dynamically updated.

{{ga-embed-pie-chart
    query=query
    options=options
    title="Sessions by country"
    is3D=pieChartIs3D
    }}

Components

Bar Chart

Creates a bar chart visualization and accepts the following configuration options.

{{ga-embed-bar-chart query=query options=options}}

Column Chart

Creates a column chart visualization and accepts the following configuration options.

{{ga-embed-column-chart query=query options=options}}

Geo Chart

Creates a geo chart visualization and accepts the following configuration options. This component lazy-loads the Google Maps Geocoding API.

The region property can be dynamically updated and is validated before the chart is updated to ensure a valid region code is used.

{{ga-embed-geo-chart query=query options=options region=region}}

Line Chart

Creates a line chart visualization and accepts the following configuration options.

{{ga-embed-line-chart query=query options=options}}

Pie Chart

Creates a pie chart visualization and accepts the following configuration options.

To transform a pie chart into a donut chart, simply add a value for the pie hole.

{{ga-embed-pie-chart query=query options=options pieHole=0.4}}

Table

Creates a table visualization and accepts the following configuration options.

{{ga-embed-table query=query options=options}}

Loading State

Each visualization has a loading state class of .ga-embed-visualization-loading, which you can customize in your CSS. The classes set on visualizations allow for custom loading states per visualization.

<div id="ember123" class="ga-embed-visualization ga-embed-chart ga-embed-line-chart ga-embed-visualization-loading">...</div>

Auto Resizing

By default, visualizations auto resize on window resize. To disable auto resizing, set responsiveResize=false on the visualization.

{{ga-embed-line-chart query=query options=options responsiveResize=false}}

Debouncing

When dynamically updating many properties on a visualization, it may be beneficial to debounce executing a new render. To do so, the visualization accepts a debounce value in milliseconds (ms).

{{ga-embed-line-chart query=query options=options debounce=100}}

View Selection

The ga-embed-view-selector component allows the user to select a view from any property they are authorized on. Add the view selector component to your template.

{{#if gaEmbed.isAuthorized}}
  {{ga-embed-view-selector ids=(mut viewIds) onChange=(action 'customAction')}}
{{/if}}

Use the mutable property in your queries:

{{ga-embed-pie-chart
    query=(hash
      ids=viewIds
      // ...
    )}}

Querying the Reporting API

The gaEmbed service enables a quick method to query data from analytics without directly using a visualization. This can be useful for querying the Google Analytics Reporting API and using the data in your own custom components.

get(this, 'gaEmbed').getData({
  'ids': 'YOUR_PROPERTY_ID',
  'metrics': 'ga:sessions',
  'dimensions': 'ga:date',
  'start-date': '30daysAgo',
  'end-date': 'yesterday'
}).then(data => {
  console.log(data);
}).catch(err => {
  console.log(err);
});

Using Google Analytics Embed API

Contributing

A crude dummy app demonstrates all the functionality of the addon. To view the dummy app, clone the repo and simply create a .env file with the following information:

# .env
GOOGLE_API_KEY=YOUR_API_KEY
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID

Then start the server using:

ember serve
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].