如何在VueJS中解雇Facebook像素

时间:2017-06-20 20:31:49

标签: javascript facebook vue.js facebook-pixel

使用正确的代码进行更新:

<script>
        export default {
            mounted() {
    //            this.comments_data = this.comments;
            },
            props: ['type'],
            data() {
                return {
    //                type: [],
                    email: '',
                    error_found: false,
                    email_error: '',
                    already_subscribed: '',
                    subscribed: false,
                }
            },
            methods: {
                subscribe(){
                    var vm = this;
                    vm.error_found = false;
                    vm.email_error = '';
                    vm.already_subscribed = '';
                    window.fbq('trackCustom', 'Custom Event Name Goes Here', {value: 1.00, currency: 'USD'});
                },
            },
        }
    </script>

当有人点击使用VueJs的订阅按钮时,我试图解雇FB Pixel。 Code&#34; vm.fbq.push(&#39; track&#39;,&#39; Even Name to here&#39;,{value:1.00,currency:&#39; USD&#39;}); &#34;一旦有人点击订阅按钮,则不会触发。我已经尝试了一切,但没有运气。有人点击按钮后,是否有人知道如何从VueJS发起Facebook像素事件?

<button @click="subscribe" class="btn btn-success btn-block">
    Submit
</button>

这是我的VueJS代码

<script>
    export default {
        mounted() {
//            this.comments_data = this.comments;
        },
        props: ['type'],
        data() {
            return {
//                type: [],
                email: '',
                error_found: false,
                email_error: '',
                already_subscribed: '',
                subscribed: false,
            }
        },
        methods: {
            subscribe(){
                var vm = this;
                vm.error_found = false;
                vm.email_error = '';
                vm.already_subscribed = '';
                vm.fbq.push('track', 'Even Name goes here', {value: 1.00, currency: 'USD'});
            },
        },
    }
</script>

1 个答案:

答案 0 :(得分:1)

假设您已在the normal manner中加载了FB像素基码,您可能需要window.fbq,而不是vm.fbqfbq不属于您的组件。