Mobile app version of vmapp.org
Login or Join
Ravi8258870

: How to make analytics refresh after certain event? I have a form which submits using AJAX. My client requested analytics to be updated with a new URL when submit is successful, so they can

@Ravi8258870

Posted in: #Ajax #GoogleAnalytics #Iframe

I have a form which submits using AJAX. My client requested analytics to be updated with a new URL when submit is successful, so they can get statistics on completion vs abandonment of that form.

The analytics code they sent me looks like this

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-00000000-1', 'auto');
ga('send', 'pageview');

</script>


I'm thinking I should use an iframe with this code inside the page to trigger the analytics under a new URL. The iframe page url would have the word success in it so it can be useful in their reporting.

I like the iframe approach because it allows me to call the analytics without refreshing the entire page. I could refresh when the 'success' event occurs, but in a multi-step process, with go-forward and go-back + animation, I am not able to refresh conveniently. I like the iframe solution because it accommodates that flexibility should I need it.

Is that a good solution, or should I be doing it differently?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Nimeshi995

You don't need to use an iframe. This tracking code is for universal analytics. There are a few ways you can push this into Google Analytics:

1) Trigger an Event on submit

You can use Javascript for this or jQuery

$('#button').on('click', function() {ga('send', 'event', 'button', 'click','Form Completed');});


2) Trigger a Virtual Pageview on submit

ga('send', 'pageview', {'page': '/form-completed','title': 'Page Name - Form Completed'});


Both have pros and cons. With Events you cant really set up goal funnels. With Virtual Pageviews you will generate extra pageviews which will mess with your bounce rate.

P.S.

I would also look into using Google Tag Manager. It will help you set these things up without having to write too much code. Its not as easy as Google wants us to think it is but once you get used to it is great.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme