我想在PHP表单成功提交后添加一个事件(已购买脚本)。我找到了在成功时触发的PHP函数,并标记了我认为要放置分析代码的位置...
function emailSuccessfullySent() {
global $translations, $lang, $options, $fdata, $is_ajax;
// redirect to custom "success" page if it's been set
if ( !empty($options['redirect_url'])) {
if (!$is_ajax) {
header('Location: '.$options['redirect_url']);
} else {
echo json_encode(array('redirect' => array($options['redirect_url'])));
}
exit;
}
// if no redirect has been set, echo out the success message
if ($is_ajax) {
echo json_encode(array('success' => array($translations->form->success->title->$lang)));
// analytics code here
} else {
echo '<h2>'.$translations->form->success->title->$lang.'</h2>';
// analytics code here
}
removeUploadsFromServer();
}
...但是我不确定如何触发JS事件:
ga('send', 'event', 'Form Button', 'submit', 'Feedback');
var_dump()
进行测试,以确保一切都正常运行。 - GreatBlakes$result = wp_remote_get($getString);
是 WordPress 特定的。使用此答案中提供的代码作为替代方案似乎可行:https://dev59.com/1HM_5IYBdhLWcg3ww2Gb。 - Nick Mischler