Skip to content

Instantly share code, notes, and snippets.

@jg314
Last active March 5, 2017 19:42
Show Gist options
  • Save jg314/5430f002c7be986d5f9c to your computer and use it in GitHub Desktop.
Save jg314/5430f002c7be986d5f9c to your computer and use it in GitHub Desktop.
Google Analytics tracking code for virtual pageviews for Gravity Forms submissions that don't send users to a new page.
<!--
The js code snippet below should be placed in the confirmation text for a Gravity Form that does not send to a thank you
page on submission, such as a sidebar or footer email newsletter signup form.
* This snippet will work for forms that submit via both ajax and non-ajax.
* This snippet will work with plugins such as Google Analytics for WordPress by MonsterInsights.
* This snippet will work for Universal Analytics, but not Classic Analytics.
You can read more about tracking pageviews at https://developers.google.com/analytics/devguides/collection/analyticsjs/pages.
-->
<!-- Make sure to turn off auto-formatting within the Gravity Forms confirmation edit screen -->
<script type="text/javascript">
var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
if ( typeof ga == 'function' ) {
// Change '/newsletter-signup-confirmation/' to a URL that makes sense for your virtual pageview
ga( 'send', 'pageview', '/newsletter-signup-confirmation/' );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment