Michael Giovanni Pumo
Michael Giovanni Pumo

Reputation: 14784

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.

Upvotes: 0

Views: 212

Answers (1)

ztadic91
ztadic91

Reputation: 2804

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');

Upvotes: 1

Related Questions