简体   繁体   中英

How to track form submit as page view in Google Analytics?

I have a basic AJAX form. On successful submission, I'd like to set the success message as a page view in GA.

I'm trying this:

window.ga('send', 'pageview', 'My Form', 'submit')

I've heard I need to use Google Tag Manager, but I'd rather simply use the existing GA if I can already in place.

Advice on the best and most simple approach for this would be great. Thanks.

The pageview tracking format through the ga object is:

ga('send', 'pageview', [page], [fieldsObject]);

where page value should begin with a / . Reference here .

In your case it would be something like:

ga('send', 'pageview', '/form-submitted', [fieldsObject]);

The other option would be to track virtual pageviews . The syntax for tracking virtual pageviews is:

ga('set', 'page', '/form-submitted');
ga('send', 'pageview');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM