tomasbasham / ember-cli-analytics

An ember-cli addon to interface with analytics services and external integrations
MIT License
8 stars 9 forks source link

instantiate: false means integrations can't get access to app #14

Open jamesarosen opened 6 years ago

jamesarosen commented 6 years ago

I want to override integration:google-analytics to supply some default common values:

// app/integrations/google-analytics.js
import GA from 'ember-cli-analytics/integrations/google-analytics'
import { inject as service } from '@ember/service'

export default GA.extend({
  session: service(),

  trackEvent(options = {}) {
    options = Object.assign({}, options, {
      dimension1: this.get('session.user.name'),
      dimension2: this.get('session.user.timeZone'),
    })
    return this._super(options)
  }
})

That blows up because the integration doesn't have an owner.

I can sort of get around this by doing the override on service:analytics, but that could be problematic if different integrations need different formats.

tomasbasham commented 5 years ago

I believe I have a fix for this that involves updating the way the base addon works. Namely I propose changing how the integrations are instantiated here to something like the following:

const adapterObject = adapter.create({ adaptable: this, config });
setOwner(adapterObject, getOwner(this));

return adapterObject;

Then updating this addon such that the insertTag methods are not called on init but instead sequentially invoked from the createAdapters methods after they have been activated.

Does this sound sensible to you or would you propose something more enlightened? I must admit I've not touched ember in about a year so I'm unfamiliar with all the advancements made.