Sometimes I see (NaN) as the value?

in
Subscribe to Sometimes I see (NaN) as the value? 8 posts, 4 voices



tysonlee19 Scriptwright

This is a great script, much better than similar alternatives. But sometimes I see (NaN) as the value, instead of the actual number. Any ideas?

Thanks,
Tyson

 
Brendan Hall... User

A colleague of mine (who knows a bit about javascript, unlike me!) solved this problem.

The issue is that the following line:

var absoluteSource = rowCells[2].textContent.replace(/\s/g, '');

is incorrect and should be:

var absoluteSource = rowCells[2].textContent.replace(/,/g, '');

It works fine when you modify the script.

 
tysonlee19 Scriptwright

Awesome, thanks! Also, if you want to skip over the % Change rows when comparing dates, you can edit the script like this:

function calcAbs() {
var statTableRows = document.getElementById('f_table_data').rows;
for(var i = 1; i < statTableRows.length; i++) {
var rowCells = statTableRows[i].cells;


var isChangeRow = rowCells[1].textContent;
if(isChangeRow.indexOf("Change") > -1){
//skip the % Change row
}
else {
var absoluteSource = rowCells[2].textContent.replace(/,/g, '');
for(var j = 3; j < rowCells.length; j++) {
var percentSource = rowCells[j].textContent.replace(/\s/g, '');
if(percentSource[percentSource.length - 1] == '%') {
percentSource = parseFloat(percentSource.replace('%', '').replace(',', '.'));
rowCells[j].innerHTML += '(' + Math.round((absoluteSource / 100) * percentSource) + ')'
}
}
}
}
}

 
Brendan Hall... User

I tried this addition to the script, but it stopped it from working at all. I have reverted to the previous version again.

 
Brendan Hall... User

Another point about the script.
You should exclude the "content-related" reports from the script, by adding the following URLs to the "Excluded Pages" section of the Greasemonkey interface for this script:
"https://www.google.com/analytics/reporting/top_content*"
"https://www.google.com/analytics/reporting/content_titles*"
"https://www.google.com/analytics/reporting/content_drilldown*"
This is because the calculation of the absolute number for the bounce rate metric in these content reports is misleading and incorrect. The bounce rate is calculated by dividing the number of bounces into the number of entrances for a page, not the total number of pageviews.
Therefore, the bounce rate metric calculation will be correct for all other "visit-based" metrics and the "top landing pages" report.

 
Vasiliy Aksy... Script's Author

Thanks everybody! Sorry for waiting, i didn't received notifications about topics and comments, but now will : )

tysonlee19 tell me please at what page you get NaN values, Brendan Hall's changes is not correct, resulting value will be wrong! And i made changes to "% Change" detection, now it should works in all international GA interfaces

 
Brendan Hall... User

Thanks for the revised script - seems to work perfectly now!

 
MarcosR User
FirefoxWindows

Hi

I am very interested in this function --

Do I need to copy and past this code into all of my webpages?

// ==UserScript==
// @name Google Analytics Absolute Conversion
// @namespace http://artyv.ru
// @version 2.1
// @description Converts percent values to absolute values in tables
// @include https://google.com/analytics/reporting/*
// @include https://*.google.com/analytics/reporting/*
// @exclude https://google.com/analytics/reporting/top_content*
// @exclude https://*.google.com/analytics/reporting/top_co...*
// @exclude https://google.com/analytics/reporting/content_...*
// @exclude https://*.google.com/analytics/reporting/conten...*
// @exclude https://google.com/analytics/reporting/content_...*
// @exclude https://*.google.com/analytics/reporting/conten...*
// ==/UserScript==

function calcAbs() {
var statTableRows = document.getElementById('f_table_data').rows;
for(var i = 1; i < statTableRows.length; i++) {
if (statTableRows[i].className.indexOf('comparison_values') > -1) continue;
var rowCells = statTableRows[i].cells;
var absoluteSource = rowCells[2].textContent.replace(/[^\d]/g, '');
for(var j = 3; j < rowCells.length; j++) {
var percentSource = rowCells[j].textContent.replace(/\s/g, '');
if (percentSource[percentSource.length - 1] == '%') {
percentSource = parseFloat(percentSource.replace('%', '').replace(',', '.'));
rowCells[j].innerHTML += '(' + Math.round((absoluteSource / 100) * percentSource) + ')';
}
}
}
}

if(document.getElementById('f_table_data')) {
calcAbs();
document.getElementById('Table').addEventListener('DOMSubtreeModified', calcAbs, false);
}

And where at the bottom before the GA code??

Or should it automatically work if this set of tools is downloaded? http://www.vkistudios.com/tools/firefox/betterga/

Thanks

Marcos