Josh Balcitis
Josh Balcitis

Reputation: 498

How to get Google Analytics to show the proper title for the pages in a single page application?

I am currently developing a single page application and have recently added the google tracking number and functionality to send to data to analytics. The code itself is behaving as expected and the data is being sent but google analytics isn't showing the correct page title even though the title itself is conforming to google's standards (i.e. under 60 characters, brand separated by a pipe, etc). Instead the generic title that is on the page before the app loads is being used, which makes it hard to track performance of certain pages in the app. I suspect this has something to do with the way google is crawling the app when getting the data for its analytics because when searching for specific pages of the app in google the results show the proper page titles. Is there anyway to make google analytics do the same google search does when it comes to page titles?

Upvotes: 2

Views: 3224

Answers (1)

XTOTHEL
XTOTHEL

Reputation: 5198

When you add GA to your site, it will look like this:

<!-- 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 -->

What you want to do in this case, is before the "ga('send', 'pageview'); add

ga('set', {
  page: '/url-of-my-app.html',
  title: 'Title that I want'
});

Another option is for you to remove "ga('send', 'pageview');" and call it within your app when the app is loaded and changed the title.

Upvotes: 3

Related Questions