You can track your site's visitors using Google Analytics by using PageView events. Just use the ga
function to send a pageview
event by using the fullpage.js callbacks, such as afterLoad
or afterSlideLoad
.
Here's an example:
function sendPageView(pageTitle){
ga('send', 'pageview', { 'page': document.location.href, 'title': pageTitle });
}
new fullPage('#fullpage', {
// Vertical sections tracking
afterLoad: function(origin, destination, direction){
sendPageView(destination.anchor);
},
// Horizontal slides tracking
afterSlideLoad: function(section, origin, destination, direction){
sendPageView(destination.anchor);
}
});
Notice that you'll have to first include Google Analytics script as usual and load it before the fullPage.js initialization. The send event only gets recorded if you first define the Google Analytics ID.
So, a full example could look like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Page</title>
</head>
<body>
<!-- Google Analytics -->
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<script>
function sendPageView(pageTitle){
ga('send', 'pageview', { 'page': document.location.href, 'title': pageTitle });
}
new fullPage('#fullpage', {
// Vertical sections tracking
afterLoad: function(origin, destination, direction){
sendPageView(destination.anchor);
},
// Horizontal slides tracking
afterSlideLoad: function(section, origin, destination, direction){
sendPageView(destination.anchor);
}
});
</script>
</body>
</html>
Make sure to replace UA-XXXXX-Y
with your own Google Analytics ID for your page.
You might also find these articles relevant: