Google Analytics Search Engine Extension

Posted 2009-06-23 in JavaScript by Johann.

Google Analytics comes with its own list of search engines

Unfortunately, Google is missing many smaller search engines, as well as local versions of certain search engines.

By default, Google Analytics’ JavaScript supports the following search engines: Daum, Eniro, Naver, images.google.com, Google, Yahoo, MSN, Bing, AOL, Lycos, Ask, Altavista, Netscape, CNN, About.com, Mamma, Alltheweb, Voila, Virgilio, Live, Baidu, Alice, Yandex, Najdi, Mama, Seznam, Search.com, Szukaj, Onet, Szukacz, Yam, PCHome, Kvasir, Sesam, Ozu, Terra, MyNet, Ekolay and Rambler.

The following JavaScript adds support for 60 70 sites to Google Analytics, among those caching domains (bingj.com), social web search engines (IceRocket, Twitter, Technorati) and many ISP portals.

// Extends Google Analytics with a ton of smaller search engines for more accurate search tracking.
// Written by Johann Burkard mailto:johann@johannburkard.de <https://johannburkard.de>
// MIT license.

for(var e="abcsok,alot,aolsvc,auone,babylon,bigseekpro,bingj,blingo,blogsearch.google,charter,comcast,conduit,cuil,com.com,daemon-search,dir.mobi,duckduckgo,earthlink,friendfeed,home.nl,icerocket,icq,incredimail,info.co.uk,mail.ru,metager2,mycricket,mytelus,nifty,ninemsn,oneview,orange.co,peoplepc,reddit,reference,semager,startpagina,sweetim,t-online,twitter,uluble,vinden,virginmedia,wibeez+q|ixquick,netzero,qip.ru,tiscali+query|att.net+string|orange.es+buscar|aliceadsl,rr.com+qs|alicesuche,gougou,technorati+search|avantfind+Keywords|mister-wong+keywords|delicious+p|info.com+qkw|sky+term|myspace+qry|gmx,web.de+su|soso+w|ukr.net+search_query|opendns+url|baidu,niuhu+bs|baidu,niuhu+word".split("|"), l=e.length;l--;)for(var p=e[l].split(/[,+]/),k=p.length-1,m=k;m--;)pageTracker._addOrganic(p[m],p[k]);

To use the Google Analytics search engine extension, insert the following line before the call to _gat._getTracker:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("XXX");

for(var e="abcsok,alot,aolsvc,auone,babylon,bigseekpro,bingj,blingo,blogsearch.google,charter,comcast,conduit,cuil,com.com,daemon-search,dir.mobi,duckduckgo,earthlink,friendfeed,home.nl,icerocket,icq,incredimail,info.co.uk,mail.ru,metager2,mycricket,mytelus,nifty,ninemsn,oneview,orange.co,peoplepc,reddit,reference,semager,startpagina,sweetim,t-online,twitter,uluble,vinden,virginmedia,wibeez+q|ixquick,netzero,qip.ru,tiscali+query|att.net+string|orange.es+buscar|aliceadsl,rr.com+qs|alicesuche,gougou,technorati+search|avantfind+Keywords|mister-wong+keywords|delicious+p|info.com+qkw|sky+term|myspace+qry|gmx,web.de+su|soso+w|ukr.net+search_query|opendns+url|baidu,niuhu+bs|baidu,niuhu+word".split("|"), l=e.length;l--;)for(var p=e[l].split(/[,+]/),k=p.length-1,m=k;m--;)pageTracker._addOrganic(p[m],p[k]);

pageTracker._trackPageview();
} catch(err) {}</script>

If you are serious about keyword statistics and data mining, give it a try. Please email me if you have additions or comments.

DynaCloud v2 (more dynamic tag clouds) plus automatic related content

Posted 2007-08-24 in JavaScript by Johann.

I have just released version 2 of DynaCloud.

DynaCloud is a JavaScript plugin for jQuery that generates tag or keyword clouds from text on web pages and highlights matching parts once a keyword is clicked.

What’s new in DynaCloud v2

  • DynaCloud properties have been moved to the jQuery.dynaCloud object.
  • Only one tag/keyword can be active at a time (switchable).
  • Automatic wordStats integration (switchable).

Demo

wordStats

Jean-François Hovinne’s wordStats plugin is quite amazing.

[wordStats] tries to determine what a page is about by computing the density of its keywords.

While DynaCloud is good at finding key words, wordStats is good at determining the topic of a page. Jean-François uses this to great effect to transparently retrieve related blog posts. Of course, this is all client-side and on-the-fly.

I like wordStats, so DynaCloud now offers transparent integration of wordStats. If the wordStats JavaScript is available, wordStats will be used. If not, the default DynaCloud algorithm is used.

highlight: JavaScript text higlighting jQuery plugin

Posted 2007-09-15 in JavaScript by Johann.

Text higlighting is part of DynaCloud – where tags/keywords are automatically highlighted once they’re clicked – so I took that code and made it a stand-alone JavaScript text highlighting jQuery plugin.

Demo

Each of the links will highlight the corresponding word.

Remove highlights again.

Usage

Add highlight

Download jquery.highlight-5.js (2 KB) and add it to your page after jQuery. A Closure Compiler compressed version (1 KB) is also available.

Style the highlight class

Create an entry in your style sheet for the highlight class.

.highlight { background-color: yellow }

Highlight terms

Call the highlight function with the text to highlight. To highlight all occurrances of “bla” (case insensitive) in all li elements, use the following code:

$('li').highlight('bla');

Remove highlighting

The highlight can be removed from any element with the removeHighlight function. In this example, all highlights under the element with the ID highlight-plugin are removed.

$('#highlight-plugin').removeHighlight();

Forks and Extensions

Changelog

  • 2014-01-11: Bugfix for character expansion during uppercasing. Thanks Guido Jansen.
  • 2009-02-22: Bugfix for one or two strange problems with IE. Also made API easier to use.
  • 2008-06-04: Bugfix for incorrect DOM normalization. Thanks Georgy.
  • 2007-09-15: Initial release.

26 comments

inc: A super-tiny client-side include JavaScript jQuery plugin

Posted 2007-10-04 in JavaScript by Johann.

Is 2007 2015 going to be the year of the JavaScript client-side include? After Mark Nottingham’s HInclude and the equally cool purple-include, I thought it was time to do something new.

How about

  • declarative inclusion of remote content
  • pre- and post-inclusion callbacks to transform content
  • all this in less than 250 B after GZIP?

inc does this.

Demo

  • Replace this text with a mildly amusing text.
  • Include another text snippet and uppercase it.
  • This pseudo text will be replaced on load.
  • Test callback method.

Usage

Add the inc JavaScript after a recent jQuery build.

<script type="text/javascript" src="jquery-1.6.3.js"></script>
<script type="text/javascript">(function(a){a.fn.inc=function(b,c,d,e){return this.length&&b?this.each(function(){e=a(this);a.ajax({url:b,success:function(f,g,h){e.html(a.isFunction(c)?c(f,b):f);a.isFunction(d)&&d(b,g,h)}})}):this};a(function(){a('[class*="inc:"]').each(function(){var b=/inc:(\S+)/.exec(this.className||"");b&&a(this).inc(unescape(b[1]))})})})(jQuery);</script>

I recommend inlining the script since it’s so small. If you have your own scripts to concatenate and minify JavaScript files, you can download jQuery inc in its uncompressed form.

Automatic inclusion

If you would like to have some content automatically included once the page is loaded, use the inc CSS class and add the resource to load. The URI must be URL-encoded.

<p class="inc:footer.html">This text will be replaced
    with footer.html</p>

<p class="small inc:footer.html inactive">This text will
    be replaced with footer.html as well</p>

<p class="inc:la%20la%20la.html">This text will be replaced
    with “la la la.html”</p>

Programatic includes

You can use the jQuery.inc function to include resources. It takes three arguments, the URL to load, an optional function that is called with the content of the URL and an optional function that is called once the content is included.

<p onclick="$(this).inc('something.html');">Include something.</p>
$('#bla').inc('bla.html', function(a) { return a.toLowerCase() });

$('#bla').inc('bla.html', null, function() {
    alert('content is now live') });

License

MIT license.

History

I have been doing client-side includes for a while on my home page and later on the “page not found” page.

Changelog

  • 2015-02-13: Updated and checked with various jQuery versions between 1.2.6 and 2.1.3. Removed alternative code for IE because jQuery can use the native XMLHttpRequest object instead of ActiveX controls.
  • 2011-09-11: Update for newer jQuery versions plus various optimizations. Saving almost 100 B.
  • 2008-01-22: Pages would even be included if no elements were matching. Added post-inclusion callback.
  • 2007-12-19: Fixed two bugs in Internet Explorer.
  • 2007-12-11: jQuery 1.2 broke inc.
  • 2007-10-09: Made even smaller and used more jQuery functionality.
  • 2007-10-04: Initial release.

8 comments

Pages

Page 1 · Page 2 · Page 3 · Page 4 · Page 5 · Next Page »

Subscribe

RSS 2.0, Atom or subscribe by Email.

Top Posts

  1. DynaCloud - a dynamic JavaScript tag/keyword cloud with jQuery
  2. 6 fast jQuery Tips: More basic Snippets
  3. xslt.js version 3.2 released
  4. xslt.js version 3.0 released XML XSLT now with jQuery plugin
  5. Forum Scanners - prevent forum abuse
  6. Automate JavaScript compression with YUI Compressor and /packer/

Navigation