E-commerce

All e-commerce features are built-in in the plugin, so there’s no need to require any e-commerce libraries: just enable the e-commerce features from the plugin configuration

  1. import Vue from 'vue'
  2. import VueAnalytics from 'vue-analytics'
  3. Vue.use(VueAnalytics, {
  4. id: 'UA-XXX-X',
  5. ecommerce: {
  6. enabled: true
  7. }
  8. })

It is also possible to use the Enhanced E-commerce library just by changing the configuration like so

  1. Vue.use(VueAnalytics, {
  2. id: 'UA-XXX-X',
  3. ecommerce: {
  4. enabled: true,
  5. enhanced: true
  6. }
  7. })

Finally it’s possible to pass additional options during the installation of the library

  1. Vue.use(VueAnalytics, {
  2. id: 'UA-XXX-X',
  3. ecommerce: {
  4. enabled: true,
  5. options: { ... }
  6. }
  7. })

Usage

All e-commerce features are accessable via the ecommerce object

  • addItem
  • addTransaction
  • addProduct
  • addImpression
  • setAction
  • addPromo
  • send

Remember that not all methods are included in the E-commerce or the Enhanced E-commerce, so please check the relative documentation in the Google Analytics dev guide.

  1. <template>
  2. <div>
  3. <button @click="addItem">Add item!</button>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'myComponent',
  9. methods: {
  10. addItem () {
  11. this.$ga.ecommerce.addItem({
  12. id: '1234', // Transaction ID. Required.
  13. name: 'Fluffy Pink Bunnies', // Product name. Required.
  14. sku: 'DD23444', // SKU/code.
  15. category: 'Party Toys', // Category or variation.
  16. price: '11.99', // Unit price.
  17. quantity: '1' // Quantity.
  18. })
  19. }
  20. }
  21. }
  22. </script>