jquery - Google Analytics on a single page without hashes -


i operate website consists of single page. navigation bar has 5-6 sections (like references, contact, t&c), , click on of them scrolls down appropriate section (div). not loaded dynamicly.

due used js (smooth scrolling etc.), url hash not change while scrolling or link-clicking. there way track users navigation in google analytics?

i have tested several answers here on so, require url hash change.

this taken from:here

read below, , depending on how site setup, use scroll triggered ajax calls send below "pageview" call, or that. hope helps.

single page application tracking - web tracking (analytics.js)

this guide describes how use analytics.js track pages on sites content loaded dynamically without traditional full page loads.

the analytics.js snippet part of universal analytics. if you're using classic analytics (ga.js) visit upgrade center learn how migrate property analytics.js. overview

a single page application (spa) web application or website loads of resources required navigate throughout site on first page load. user clicks links , interacts page, subsequent content loaded dynamically. application update url in address bar emulate traditional page navigation, full page request never made.

the default analytics.js snippet code works traditional websites because snippet code run every single time users load new page. however, single page application you're loading new page content dynamically rather full page loads, analytics.js snippet code runs once. means subsequent (virtual) pageviews must tracked manually new content loaded.

tracking virtual pageviews

to track dynamically loaded content distinct pageviews can send pageview hit google analytics , specify document path setting page field.

ga('send', 'pageview', '/new-page'); 

the page field represents path portion of url , should begin slash. page value same path portion of url shown in browser's address bar, doesn't have be. since websites load content dynamically update hash portion of url user navigates, several different url paths may point same resource. in these cases, it's best choose canonical url , ever send page value google analytics.

for example, consider website "about us" page can reached via of following urls:

/about.html /#about.html /home.html#about.html 

to avoid duplication in reports, it's best track of these pageviews /about.html.

setting page data multiple hits

specifying page value in pageview hit send page value google analytics hit only; not update page value stored on tracker object itself. can problematic if send other hits (e.g. events or social hits) , don't explicitly include current page value. in such cases, google analytics associate hits whatever url present @ time of initial page load.

to avoid issue, it's best update tracker object new page information prior sending hits. ensure hits associated correct page data.

to update tracker object, use set method:

ga('set', 'page', '/new-page'); if want update more page field, can pass object of key/value pairs set method.

ga('set', {page: '/new-page', title: 'new page' 

}); once tracker has been updated proper data new page, can send hit without overriding page related parameters. example:

ga('send', 'pageview'); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -