Skip to content

Instantly share code, notes, and snippets.

@BrockReece
Created April 15, 2017 17:33
Show Gist options
  • Save BrockReece/f937805d07a52be491246dd27032c5a1 to your computer and use it in GitHub Desktop.
Save BrockReece/f937805d07a52be491246dd27032c5a1 to your computer and use it in GitHub Desktop.
Vue form analytics mixin
import { mapActions } from 'vuex'
export default {
methods: {
...mapActions([
'updateInputFocus',
]),
lastInputFocus(e) {
if (!e.srcElement.name) return
this.updateInputFocus(e.srcElement.name)
},
setFocusListner() {
this.$nextTick(() => {
this.$el.querySelectorAll('input').forEach((input) => {
input.addEventListener('focus', this.lastInputFocus)
})
this.$el.querySelectorAll('textarea').forEach((input) => {
input.addEventListener('focus', this.lastInputFocus)
})
})
},
sendAnalytics() {
this.$http.post(this.analyticsEndpoint, {
type: this.analyticsType,
data: {
...this.analytics,
errors: this.errors.map(error => ({ text: error })),
},
})
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment