1

I used a custom JavaScript to import currency conversion rate from yahoo to my google analytics because GA does not have Macau pataca as a currency, so transaction revenue zero in reports.

here is the code I used,

function getRate(from, to) {
  var script = document.createElement('script');
  script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
  document.body.appendChild(script);
}
function parseExchangeRate(data) {
  var name = data.query.results.row.name;
  var rate = parseFloat(data.query.results.row.rate, 10);
  alert ("Exchange rate " + name + " is " + rate);
}
return getRate("MOP", "USD");

However, it gives the this error -

Error at line 7, character 1: Parse error. ')' expected

Highly appreciate if you could help me to find my error here.

Thank you very much

cool_kid
  • 337
  • 1
  • 3
  • 13
  • The script seems to be working fine. You have to use it in the HTML body (or after the DOM is ready) since it appends to the body, also you cannot return outside a function, and in any case your parseExchangeRate callback does not return a value (instead it issues an alert). But those problems would not cause the error you see, so this is caused by something else. – Eike Pierstorff Jun 02 '16 at 07:07
  • Dear Eike, Thank you so much for the comment! Highly appreciate, I will add a comment if I fix this somehow. Thank you – cool_kid Jun 03 '16 at 04:05

0 Answers0