在Ajax表单中设置Google Analytics事件

时间:2022-10-13 15:18:39

I am trying to set a Google Analytics event on a lightbox contact form of a WP plugin.

我正在尝试在WP插件的灯箱联系表单上设置Google Analytics事件。

I have added the onSubmit call inside the and although it renders well without problem, the events are not logged into Analytics

我已在内部添加了onSubmit调用,虽然它渲染得很好但没有问题,但事件未记录到Analytics中

<form action="#" method="post" class="modal-contact_form" onSubmit="_gaq.push(['_trackEvent', 'Contact V1', \'<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ?>', '1']);">

The event seems not to log in, because there's a new Thank You lightbox window which appears after you hit Send on Contact form

该事件似乎没有登录,因为在您点击发送联系表单后会出现一个新的Thank You灯箱窗口

This is teh original code of the Thank you lightbox window

这是谢谢灯箱窗口的原始代码

            $.post( modal_contact_params.ajax_url, data, function( response ) {
                if ( response == "SUCCESS" ) {

                    $('#facebox .content form.modal-contact_form').slideUp();
                    $('#facebox .notice').remove();
                    var agent_name = jQuery("#ninety_mcf_user_name").html();
                    if(agent_name=='This Agent'){
                        $('#facebox .modal-contact_messages').html('<div class="notice success"><div><p><strong>' + modal_contact_params.i18n_sent + '</strong> ' + modal_contact_params.i18n_thanks + '</p></div></div>'
    );
}
    else
{
                        $('#facebox .modal-contact_messages').html('<div class="notice success"><div><p><strong>' + modal_contact_params.i18n_sent + '</strong>Thanks, your email has been sent to '+agent_name+'</p></div></div>'
);
                    }

                }

I am trying to insert the _gaq.push Event call at the end of Success lightbox but I can't make it

我试图在成功灯箱的末尾插入_gaq.push事件调用,但我无法做到

I have tried all sorts of combinations and none of them render, as they all produce errors on GA Debug console in Chrome

我尝试了各种组合,但没有渲染,因为它们都会在Chrome中的GA Debug控制台上产生错误

One of my many different tries

我的许多不同尝试之一

</div>' + { _gaq.push(['_trackEvent', 'Contact V1', 'Send', '1']); } +''
);

Thanks and I hope it's easy enough for SO gurus to help me.

谢谢,我希望SO大师能够帮助我。

1 个解决方案

#1


0  

I don't think you want to append the function call to the string, but execute it...

我不认为你想将函数调用追加到字符串,但执行它...

...</div>');
_gaq.push(['_trackEvent', 'Contact V1', 'Send', '1']);
...

#1


0  

I don't think you want to append the function call to the string, but execute it...

我不认为你想将函数调用追加到字符串,但执行它...

...</div>');
_gaq.push(['_trackEvent', 'Contact V1', 'Send', '1']);
...