I have bootstrap (4.3) modal in vuejs app. On modal show I want to send gtag (google analytics) data. I have tried
async created() {
//some other code
$('#modalRecommend').on('shown.bs.modal', function (e) {
this.gtagFunction('pressed', 'my cat','test label','no');
$('body').addClass('modal-recommend-open');
}).on('hidden.bs.modal', function (e) {
$('body').removeClass('modal-recommend-open');
});
}
When modal show it is showing error
Uncaught TypeError: this.gtagFunction is not a function
If I place this.gtagFunction() this outside $('#modalRecommend').on('shown.bs.modal', function (e) {.. then it is works.
Note: I have loaded a mixins in parent component where this.gtagFunction() is available. Also I have tried to add @click.native in HTML like
<img @click.native="sendAnalytics()" class="w-auto mr-2" src="/pic.png" width="120" height="40" v show="recommendRankingWorks.length > 0" data-toggle="modal" data-target="#modalRecommend" style="cursor:pointer;"/>
with
methods{
sendAnalytics: function(){
this.gtagFunction('pressed', 'my cat','test label','no');
},
}
but not fired. Only show modal