Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/vue-mixins #1

Merged
merged 11 commits into from
Feb 23, 2019
Merged

feat/vue-mixins #1

merged 11 commits into from
Feb 23, 2019

Conversation

tamer-mohamed
Copy link
Owner

Enable mixins in @ichnos/vue

Setup Vue mixin

you may need to tracking html elements using data-track* attributes.
find example below to track html elements and format gtm event before sending the event using beforeSend hook

import Vue from 'vue'
import {mixinFactory} from '@ichnos/vue'


new Vue({
    mixins: [
      mixinFactory({
        events: [
          {
            elements: ['a', 'button'],
            eventListeners: ['click'],
            mapTagNameToGTMEventName: {
              button: 'button',
              a: 'link',
            },
          },
          {
            elements: ['input', 'textarea', 'checkbox', 'radio'],
            eventListeners: ['focusin', 'focusout'],
            mapTagNameToGTMEventName: 'input',
          },
        ],
        beforeSend: (event) => ({
          event: 'gtmEvent',
          gtmEventCategory: event.category, // -> interpolated from data-trackcategory
          gtmEventLabel: event.label,
          gtmEventValue: event.value,
          gtmEventAction: event.action,
        }),
      }),
    ],
});

mixinFactory params

interface IMixinFactory {
  event: {
    elements: string[]
    eventListeners: string[]
    mapTagNameToGTMEventName: any
  },
  beforeSend(event: any): any
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant