W
W
WebforSelf2021-08-11 22:04:54
PHP
WebforSelf, 2021-08-11 22:04:54

Is it possible to handle google targets via php?

There is a google target in JS

gtag('event', 'click_button_callback', { 'event_category': 'zakaz-zvonka', 'event_action': 'zakaz-zvonka', });


All form validation and submission is built in PHP, how to send the gtag target on successful form submission?

if($this->request->method('post') && $this->request->post('callback')) {
            $callback = new stdClass();
            $callback->phone        = $this->request->post('phone');
            $callback->name         = $this->request->post('name');
            $callback->url          = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $callback->message      = $this->request->post('message');
            $captcha_code =  $this->request->post('captcha_code', 'string');

            $this->design->assign('callname',  $callback->name);
            $this->design->assign('callphone', $callback->phone);
            $this->design->assign('callmessage', $callback->message);

            /*Валидация данных клиента*/
            if (!$this->validate->is_name($callback->name, true)) {
                $this->design->assign('call_error', 'empty_name');
            } elseif(!$this->validate->is_phone($callback->phone, true)) {
                $this->design->assign('call_error', 'empty_phone');
            } elseif(!$this->validate->is_comment($callback->message)) {
                $this->design->assign('call_error', 'empty_comment');
            } elseif($this->settings->captcha_callback && !$this->validate->verify_captcha('captcha_callback', $captcha_code)) {
                $this->design->assign('call_error', 'captcha');
            } elseif($callback_id = $this->callbacks->add_callback($callback)) {
                $this->design->assign('call_sent', true);

                //Уведомим в Telegram
                if($this->settings->tg_notify==1)

                 $this->telegram_notify->sendMessageAboutСallback($callback->name, $callback->phone, 'форма заказа обратного звонка');

                // Отправляем email
                $this->notify->email_callback_admin($callback_id);

            } else {
                $this->design->assign('call_error', 'unknown error');
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
po47, 2021-08-15
@po47

If, for example, a page is returned about the successful submission of data from the form, then use the script on
this
page
: zvonka',
'event_action': 'zakaz-zvonka'
});
})
The script is used where a successful action is confirmed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question