VaroX VaroX - 5 months ago 12
Android Question

Comscore issue in Android

I´m facing an issue with the following JS method given by comscore:

function ns_onclick(q, f, u, b, o) {
var i = window,
l = i.ns_p,
m = l && l.src,
s = "&ns_",
h = document.referrer.replace(/\/$/, ""),
f = f || q.href,
o = o || "",
j = {
t: 0,
o: 0
},
e = eventURL = c1_match = c2_match = "",
c = /\bc1=[^&]+\b/i,
g = /\bc2=[^&]+\b/i,
p = (i.encodeURIComponent ? encodeURIComponent : escape),
n = "1.11111.11";


if (m && (c1_match = l.src.match(c)) && !c.test(u)) {
e += "&" + c1_match
}
if (m && (c2_match = l.src.match(g)) && !g.test(u)) {
e += "&" + c2_match
}
if (m) {
var t = l.src,
k = t.indexOf("?");
eventURL = t.substr(0, k > -1 ? k : t.length) + "?"
}
eventURL = [eventURL, u, e, s, "type=", b, s, "action=view", s, "_t=", +new Date, h ? s + "referrer=" + p(h) : "", s, "sc_sv=", n, s, "sc_href=", p(f).substr(0, 1000)].join("");

var r = q && q.target ? q.target.replace(/^_/, "") : "self",
d = new Image();

if (i[r]) {
j.t = (function(w, v, a) {
return function() {
clearTimeout(a.o);
d.onload = d.onerror = function() {
return
};
i[w].location.href = v
}
})(r, f, j);
j.o = setTimeout(j.t, 5000);
d.onload = d.onerror = j.t
} else {
i.open(f, r, o);
}
d.src = eventURL;
return false};


The way i call that method is as it follows:

<button onclick="ns_onclick(this, '', 'osp_ev=event', 'clickin');" nav-transition="none" ng-show="backButtonHiden" class="button button-icon button-clear ion-navicon-round" menu-toggle="sideMenuToggle(false)" data-tap-disabled="true"></button>


The method is called perfectly and it seems to go through all the way with no problems whatsoever. But somehow, it makes my app to crash with showing the folling error on the screen:

enter image description here

What worries me the most is that this works perfectly on iOS. It seems like Android is trying to open file, that obviously doesn´t exist... Any ideas?

EDIT: I found out that the problem is located at the following line:

i[w].location.href = v


v is "undefined", and it makes the app to crash!, as you can see... the code on the ns_onclick function is a mess, and JS is not really my field. Does anyone ever worked with Comscore analytics in a hybrid App? if so, is there any difference between using it on a web site or an app?

Answer

I finally got it! the problem wasn´t on the JS code provided by Comscore, it was located on the HTML tag. This is what i was doing:

<button onclick="ns_onclick(this, '', 'osp_ev=event', 'clickin');" nav-transition="none" ng-show="backButtonHiden" class="button button-icon button-clear ion-navicon-round" menu-toggle="sideMenuToggle(false)" data-tap-disabled="true"></button>

And this is how it should be done:

<a href="#/path" onclick="ns_onclick(this, '', 'osp_ev=event', 'clickin');" nav-transition="none" ng-show="backButtonHiden" class="button button-icon button-clear ion-navicon-round" menu-toggle="sideMenuToggle(false)" data-tap-disabled="true"></a>

As you can notice, i´ve changed the < button > tag by the < a > tag, and added the href property to it. It is mandatory to set a href to the html tag, and this can only be done through a link tag. I tryed to add the href to the button, just to give it a try, but it doesn´t work... i don´t know it is because it only works with < a > or any other reason... as i said on the question, this is actually not my field.

I hope it helps if you face the same problem.

Comments