ScreamZ / vue-analytics

Google Universal Analytics support in Vue.js
Apache License 2.0
216 stars 27 forks source link

Config Option to either track page or screenviews #24

Closed cspeer closed 6 years ago

cspeer commented 6 years ago

You have an undocumented option for trackView that would let anyone using that method manually track the view as either a page or a screenview. I thought it might be useful to have that option globally available when auto-tracking with vueRouter:

Vue.use(VueAnalytics, {
  appName: '<app_name>', // Mandatory
  appVersion: '<app_version>', // Mandatory
  trackingId: '<your_tracking_id>', // Mandatory
  debug: true, // Whether or not display console logs debugs (optional)
  vueRouter: router, // Pass the router instance to automatically sync with router (optional)
  ignoredViews: ['homepage'], // If router, you can exclude some routes name (case insensitive) (optional)
  **trackPage: true|false, // Whether you want page changes to be recorded as pageviews (website) or screenviews (app), default: false**
  globalDimensions: [ // Optional
    {dimension: 1, value: 'MyDimensionValue'},
    {dimension: 2, value: 'AnotherDimensionValue'}
  ],
  globalMetrics: [ // Optional
      {metric: 1, value: 'MyMetricValue'},
      {metric: 2, value: 'AnotherMetricValue'}
    ]
})

Setting that option to true will now dispatch a view as a pageview instead. Hope this helps :)

ScreamZ commented 6 years ago

Nice idea, I publish the patch.

Thank you for your contribution.

cspeer commented 6 years ago

Great! Thanks :) You should probably release a new version to npmjs.com too

ScreamZ commented 6 years ago

Already done yes, 1.5.0.