Monday, May 20, 2024
145
rated 0 times [  147] [ 2]  / answers: 1 / hits: 24067  / 13 Years ago, tue, september 6, 2011, 12:00:00

The site that I'm working on has really crappy title structure and can't be changed for a variety of reasons. Can I set the page title for Google Analytics via JS somehow?


More From » google-analytics

 Answers
52

The New Way



There's a (currently undocumented feature) that allows you to override the current page's title:



_gaq.push([_set, title, Your Brand New Page Title]);
_gaq.push([_trackPageview]); //will send with the overridden page title





The Old Way



Google Analytics gets the title information from document.title, so you could just set document.title before Google Analytics runs to whatever value you want it to be.



_gaq.push(function(){
var oldtitle = document.title;
document.title = More Descriptive Title;
_gaq.push([_trackPageview]);
document.title = oldtitle;
});


Tests in Chrome seem to indicate that this doesn't cause a title flicker, but your results may vary.


[#90238] Monday, September 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;