I've encountered an issue with a custom Google search engine I've integrated into my site. I have some other Google elements on the same page, such as the +1 button and G+ badge, but I've isolated and verified that the search element is, in fact, the culprit.
The problem is the following: the GET request for http://www.google.com/uds/api/ads/3.0/9f53ed6be164615d919d9e4bd4f7fe8d/search.I.js seems to fail (although searching the site still works). The dev console in Chrome says that the request is initiated by their jsapi on line 21 and has the following highlighted in red:
google.(anonymous function).d
(anonymous function)
I've tried multiple test scenarios, including inserting the search box on a completely barebones HTML page, but I get the same error. What is causing the request to fail? Is it simply something on their end (and thus unfixable)?
Edit: Relevant code
This is all taken verbatim from Google's code generators.
This goes right before </head>
<script>
(function() {
var cx = '004344714102800561193:mo5u_njahwy';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
The search box code:
<gcse:searchbox-only></gcse:searchbox-only>
Search results page code:
<gcse:searchresults-only></gcse:searchresults-only>
Do you have an ad blocker installed like Adblock Plus? I'm getting this error when I run your code in JSFiddle:
Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
It looks like that error is often caused by an ad blocker preventing the file from being loaded: Meta - What are these errors about in the Chrome console when visiting StackOverflow?
Related
this is my simple script,
<script>
window.onerror = err;
var script = document.createElement('script');
script.src = "192.186.1.1.1.1.1";
script.onerror = err;
document.body.appendChild(script);
function err(msg, loc, a, b) {
alert(msg + "/" + loc);
}
</script>
but when i load this i get,
[object Event]/undefined
when i run the same on "firebug" i get detailed error like,
NetworkError: 404 Not Found - http://localhost/XSS/192.186.1.1.1.1.1"
So how can i get a detailed error .
try-catch alos doesnt work
try {
var script = document.createElement('script');
script.src = "192.186.1.1.1";
document.body.appendChild(script);
} catch(e) {
alert(e.name);
}
does that method will work only in old browsers ?
img.src also doesnt provide fire error handler. why?
var img = new Image();
img.src="gifffff/asasa/ss" ;
Firebug is not code, but a browser diagnostic tool running on the agent's behalf. (JavaScript cannot read the result of the firebug console.)
Now, for the cases:
The Image.error event never says why the loading failed. There is no provision to include the "reason" in the HTML specification; problem solved by not being a feature to begin with.
The catch doesn't work because there was no Exception thrown by the code.
The Image is still an Image and can still be added to the DOM
regardless of if the resource (eventually) fails to load.
(The src is still set to a valid URI component - it would have thrown an exception on an invalid/unknown URI scheme.)
Having this general limitation (on any [Image] resource, even on the same origin) also prevents violation of the Same-Origin Policy - and the ability for malicious code to run various network scanning attacks.
I am running google custom search in browser it works fine. It runs fine even in emulator in Phonegap but it gives network error or it shows blank screen when the same is run on android phone. or gives this error "file:///google.com/cse?q=.... can not be found."
I am using google custom search v2 code.
The code you get for v2 of custom search looks something like this:
<script>
(function() {
var cx = 'ENGINE_ID';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
What it roughly does is creating a tag like this:
<script type="text/javascript" src="http://www.google.com/cse/cse.js?cx=ENGINE_ID">
and inserts it before other scripts on your page. So you can skip this code altogether and manually insert the above tag (with your engine id) and only <gcse:search></gcse:search> to your HTML. If the connection from file:// to http:// is still not possible, download this script (http://www.google.com/cse/cse.js?cx=ENGINE_ID) and serve it as local javascript file.
I've encountered the same problem. An one-line change in JavaScript made the file:// error go away:
// This line must take place before initializing GCSE
window.IS_GOOGLE_AFS_IFRAME_ = true;
Verified on both iOS and Android Cordova environments.
I recently installed my analytics code, but it has been saying for a while that it's not installed.
I can't think of a better place to put it. Does the script interfere with my other script (for the fade-in)?
Also, should my script be the first thing I include? (maybe after </title>?)
Hits are showing under "real-time" but not as actual visits. The tracking info still says "tracking not installed." I refreshed to make sure.
UPDATE: Google is showing my hits, and I have data... but it says that tracking is not installed. I've had this issue with Wordpress sites, but they were remedied with the use of a plug-in.
Should I try using the old tracking script? I know that one works.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Casey</title>
<meta name="description" content="" />
<meta name="keywords" content="">
<link href="home.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
if (window.localStorage && !localStorage['faded']) {
localStorage['faded'] = true;
$('body').hide().fadeIn(500);
}
});
</script>
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40498113-1', 'caseykidd.com');
ga('send', 'pageview');
</script>
</head>
The only thing I see that's "off" is
ga('create', 'UA-40498113-1', 'caseykidd.com');
should be
ga('create', 'UA-40498113-1', {'cookieDomain':'caseykidd.com'});
But I don't think that's really the problem (I think GA is just ignoring how you did it and it happily works out okay, based on your lack of subdomain in the URL). edit: oddly, the generated code within the GA interface looks like what you have, but that's not what the documentation shows. I have verified that this is apparently an undocumented syntax shortcut for setting the cookie domain.
You said you see the data in the "real time" reports so I assume your account number is correct.
My only suggestion is to wait a while for the data to show up. GA's "real time" stuff only shows some basic info. Stuff like "visit" may not be immediately available because of the nature of the dimension/metric. For example, GA (and most other tracking tools) usually don't count it as a visit until the visit is actually over. So if you went to your site to test it and then immediately went to GA to check...well the visit isn't actually over until 30 minutes after the last request to GA.
update (additional info based on your comment below and update to your question)
I don't necessarily think you need to use the old tracking script.. I don't know how it works within Google's system, but Google actually officially states that it can take up to 24 hours for everything to be completely recorded.
Also to be fair, Universal Analytics (analytics.js) is open beta phase at the moment.. it could be that they haven't gotten around to updating that verification logic, or there could be a bug in it, or it could be one of the things that take closer to 24 hours to be updated.
Again, since you are seeing data, I don't think you are doing it wrong, but for sh*ts and grins you can read the entry on verifying your web tracking setup. Are you testing on some other domain than what the web property is setup for? I think GA may not report that implementation has been verified if it has not received a request from the domain specified in the property settings. Also the the manual says it must be on the "homepage" of your site. Are you testing on the homepage or using a custom page name?
As a test I setup analytics.js code in a new web property for a domain that did not previously have any GA tracking on it, when I posted this answer. I see my data but the tracking status remains as "not installed." It has not been 24 hours for me yet, but I personally don't really care, as long as the data is coming in. Even Google's troubleshooting document entry for tracking verification just says to look at the request and verify data in the reports, so that's good enough for me.
But if it really bothers you that much, and you've waited at least 24 hours, I would suggest posting a possible bug report on the google support forums.
update 2: It's been about 18 hours, since I last checked, and the status msg has changed to "receiving data" on my test domain/web property.
When you create a Google Analytics account you're provided with the tracker script, which in my experience has always been the below:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
That uses the _gaq object, where basically you fill an array of arrays with stuff you want Google Analytics to do later, and when it loads it looks for _gaq, reads the array and executes those commands. It then replaces _gaq with an object that immediately responds to calls to .push() by executing the commands described in the array.
So for example if you added this to the array:
_gaq.push(['_trackEvent', 'Ordering', 'Clicked', 'Order Now top-left']);
Then one of 2 things would happen:
If GA hadn't loaded yet, this array would be added to the _gaq array, waiting for GA to finish loading. When GA did load it would read this and fire the trackEvent command with the parameters you included.
If GA had already loaded, then this call to .push() would cause the trackEvent command to be executed immediately, with the parameters you included.
By the way I usually simplify the example script to:
<script>
var _gaq = [
['_setAccount', 'UA-XXXXXXXX-1'],
['_trackPageview']];
(function() {
var ga = document.createElement('script'); ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
For awhile now, a piece of javascript I wrote which listens to youtube actions on a certain page worked wonderfully. I am using Youtube's iframe js api: https://developers.google.com/youtube/iframe_api_reference .
But one recent content addition, a specific youtube video, the tracking wouldn't work. The events won't fire at all.
In the console, I noticed this post message error:
Unable to post message to http://youtube.com. Recipient has origin http://www.youtube.com.
So nothing with my own code helped. Some questions here on stackoverflow suggested this is an issue with initiating new YT.player too soon, so I tried a whole bunch of things like loading the yt js api file on window load and only apply the api after, but that didn't seem to do any good either.
I know this post is 3 years old, but for those who are still searching for an answer:
Add this script and everything works fine:
<script src="https://www.youtube.com/iframe_api"></script>
I've had the same problem with jwplayer and fixed it with that script.
It took me over an hour, but the answer was right in front of me. It's actually pretty self explained: You cannot use youtube's js api to track an iframe video without www. I don't know why, it certainly does not say so in their documentation.
I tested this a few times and confirmed, as of now, tracking an iframe with the source www.youtube.com/embed/0GN2kpBoFs4 would work wonderfully while tracking youtube.com/embed/0GN2kpBoFs4 will throw:
Unable to post message to http://youtube.com. Recipient has origin http://www.youtube.com.
The confusing part of course is that both the video load and play fine. It's only the API which is not working properly.
fiddle - http://jsfiddle.net/8tkgW/ (Tested on chrome / mountain lion)
Btw, while writing this answer I came across YouTube iframe API: how do I control a iframe player that's already in the HTML? - notice this guy's fiddle. He wrote his own youtube iframe implementation (wow!). If you change the iframe source address in the fiddle to one without www, it will work. This only means youtube writes bad js. Bad bad bad!
Don't forget to add it to the whitelist:
<!-- Add the whitelist plugin -->
<plugin name="cordova-plugin-whitelist" source="npm" spec="*"/>
<!-- White list https access to Youtube -->
<allow-navigation href="https://*youtube.com/*"/>
The youtube api documentation recommend to load the api like this
var tag = document.createElement('script');
tag.src = "http://youtube.com/iframe_api";
tag.id = "youtubeScript";
var firstScriptTag = document.getElementsByTagName('script')[1];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
But getting this error:
Unable to post message to http://youtube.com. Recipient has origin http://www.youtube.com
Here is the best solution I found from [a now-dead site]:
So add this first at the top before calling the Api
if (!window['YT']) {var YT = {loading: 0,loaded: 0};}
if (!window['YTConfig']) {var YTConfig = {'host': 'http://www.youtube.com'};}
if (!YT.loading) {YT.loading = 1;(function(){var l = [];YT.ready = function(f) {if (YT.loaded) {f();}
else
{l.push(f);}};
window.onYTReady = function() {YT.loaded = 1;for (var i = 0; i < l.length; i++) {try {l[i]();} catch (e) {}}};
YT.setConfig = function(c) {for (var k in c) {if (c.hasOwnProperty(k)) {YTConfig[k] = c[k];}}};
var a = document.createElement('script');
a.type = 'text/javascript';
a.id = 'www-widgetapi-script';
a.src = 'https:' + '//s.ytimg.com/yts/jsbin/www-widgetapi-vflumC9r0/www-widgetapi.js';
a.async = true;
var b = document.getElementsByTagName('script')[0];
b.parentNode.insertBefore(a, b);})();}
//===========THEN=============================
function onYouTubeIframeAPIReady () {// do stuff here}
I am trying to track my pages via google analytics, here is my code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XXXXXXXXXX']);
_gaq.push(['_setDomainName', 'somesite.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
(function ($) {
// Log all jQuery AJAX requests to Google Analytics
$(document).bind('ajaxComplete', function(event, xhr, settings){
console.log('ajax Request');
console.log(settings.url);
_gaq.push(['_trackPageview', settings.url]);
});
})(jQuery);
On each ajax request I can see the console has values
ajax Request
url of the page
it means _gap.push is working (as there is no js error on page). But when I am checking my req/res via Live HttpHeaders there is no req/res to google analytics, How to track it?
here is the screenshot in firebug
The point in _gaq.push is that, until Google Analytics is actually loaded, "_gaq" is just a normal array. That is: the lack of errors is indeed expected, regardless of whether or not it is "working" in the sense of triggering a request to Google.
The way Google Analytics works is not via ajax (or at least, there is no specific implementation detail regarding how the request will be sent). The method usually used is to create an Image element with the tracking data included in the query string of that image's URL. After all, the page doesn't care what response Google Analytics has, it just wants to send its data and go!
Rather than using LiveHttpHeaders, I would check the 'Network' panel of your developer tools -- if you have the Javascript console, you probably have access to that as well. You should be able to see all of the details of the requests on that panel.
You can also use the debug version of ga.js to diagnose errors. It prints things like "Invalid tracking code" and so on to the Javascript console.
Search for "Debugging with ga_debug.js" on this page:
https://developers.google.com/analytics/resources/articles/gaTrackingTroubleshooting
Look at the http headers sent - I use HttpFox - and filter for 'utm'. Look at the query string (httpfox breaks this out into a table for you) and you can see all of the utm parameters of the hit - account number (utmac), page (utmp), etc. If any of the utm params are unfamiliar, check this reference. This sort of simulation and analysis of the image requests sent to google's servers is very useful for debugging Google Analytics problems.