How to Use Scroll Tracking in WordPress with Google Analytics
Check Out More At: WP Beginner
WordPress: Best WordPress Plugins | WordPress Tutorials
How to Use Scroll Tracking in WordPress with Google Analytics
Product Image | Product Name / Primary Rating / Price | Primary Button / Description |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Elementor is an amazing website builder plugin for WordPress. Elementor makes it easy to create beautiful and high converting websites yourself without having to learn code.
Gravity Forms is a WordPress plugin that creates powerful forms quickly and easily, with drag-and-drop fields, custom notifications and confirmations, and custom styling capability.
Kadence Theme is a powerful, intuitive and flexible WordPress theme that offers an expansive set of features and customization options.
It includes a robust page builder, beautiful design options, mobile-friendly responsiveness, powerful SEO tools and optimized performance for faster loading times.
It's perfect for creating stunning websites without needing to write any code.
Cloudways is a managed cloud hosting platform that simplifies cloud infrastructure deployment and management.
It provides an intuitive dashboard, automated backups and optimized stack for speedy performance. It also provides 24x7 support with multiple server locations, enabling businesses to host their applications quickly and securely.
If you want to know how popular your website is, you need to track yourscrolls. Google Analytics can help you track how often users scroll down your pages. This information can be useful in understanding what content is most popular on your site.
To set up scroll tracking in WordPress with Google Analytics, you need to add a few code snippets to your website. First, you need to create a Google Analytics account and obtain your tracking code. Next, you need to install a plugin like WPForms or Gravity Forms.
Once you have the plugin installed, you need to add the following code to your forms:
function wpua_scroll_track_ forms ( $ form_id ) {
$ form = GFAPI:: get_ form ( $ form_id ) ;
$ fields = $ form [ ‘fields’ ] ;
foreach ( $ fields as & $ field ) {
if ( $ field [ ‘type’ ] == ‘text’ ) {
$ field [ ‘cssClass’ ] = ‘wpua-scroll- track ‘ ;
}
}
$ form [ ‘fields’ ] = $ fields ;
return $ form ;
}
add_filter ( ‘gform_pre_render_’ . $ form_id , ‘wpua_scroll_track_ forms’ ) ;
function wpua_scroll_track_ fields ( $ form ) {
?>
( function ( $ ) {
$ ( document ) . ready ( function ( ) {
$ ( '.wpua-scroll- track ' ) . each ( function ( index ) {
var field_id = $ ( this ) . attr ( 'id' ) ;
var form_id = $ ( this ) . closest ( 'form' ) . attr ( 'id' ) ;
$ ( this ) . scroll ( function ( ) {
var scroll_percent = ( $ ( this ) . scrollTop ( ) / $ ( this ) [ 0 ] . scrollHeight ) ;
gtag ( 'event' , 'scroll' , {
'event_category' : 'Scroll' ,
'event_label' : field_id ,
'value' : scroll_percent ,
'non_interaction' : true
} ) ;
} ) ;
} ) ;
} ) ;
} ( jQuery ) ) ;
}
add_action ( ‘gform_fields_’ . $ form_id , ‘wpua_scroll_track_ fields’ , 10 , 2 ) ;
Now that you have the code in place, every time a user scrolls on a text field in a form, Google Analytics will track the scroll percentage.
Scroll tracking is a great way to see how far down the page your visitors are scrolling. This information can be very useful in understanding what content is resonating with your audience and what isn’t.
The first thing you need to do is install and activate the Google Analytics for WordPress plugin. For more information, see our article on how to install a WordPress plugin.
Once the plugin is activated, you need to edit the settings. Go to Settings » Google Analytics and enter your Google Analytics tracking code in the provided field.
Next, you need to select the ‘Events’ tab and make sure that the ‘Track Outbound Links’ and ‘Track Downloads’ options are enabled.
Now that the plugin is properly configured, you can start tracking scroll events. To do this, go to Behaviour » Events » Overview.
This will bring up a list of all the events that Google Analytics has tracked. You can then click on ‘View Full Report’ to see a detailed breakdown of the events.
With the Google Analytics for WordPress plugin, you can also track how far down the page your visitors are scrolling. To do this, go to Behaviour » Events » Top Events.
This will bring up a list of events, sorted by how often they occurred. Scrolling events will be listed under the ‘Engagement’ heading. You can then click on ‘View Full Report’ to see a detailed breakdown of the events.
By understanding how far down the page your visitors are scrolling, you can make better decisions about what content to include on your website. This information can also be used to improve the design of your website to make sure that your visitors are seeing the most important information first.