External Interface, Internet Explorer and Time Wasted

Dear Googlers,

I leave this message for you in the case that you encounter a similar obstacle to your productivity. Internet Explorers 6, 7 and 8 do not like uppercase letters (or hyphens) in the object ID when embedding a swf into the page if you then plan on using the code with ExternalInterface. They do not like it with SWFObject or with the simple old fashioned object tag. The solution was elusive, but there is some help on the ghettocooler.net Treasure Trove.

The following code will work in Firefox and Safari, but will mysteriously have a problem in Internet Explorer:

<script language="javascript">
function submitLemon() {
   var swf = document.getElementById("myContent");
   swf.iCanHasParameter('lemon');
}

swfobject.embedSWF("movie.swf", "myContent", "800", 
                   "100%", "9.0.124", null, {}, {bgcolor: '#ffffff'});
</script>

It will however work if you replace the upper case letter with its lowercase equivalent:

<script language="javascript">
function submitLemon() {
   var swf = document.getElementById("mycontent");
   swf.iCanHasParameter('lemon');
}

swfobject.embedSWF("movie.swf", "mycontent", "800", 
                    "100%", "9.0.124", null, {}, {bgcolor: '#ffffff'});
</script>
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

1 comment


August 1, 2010
me said:

http://labs.hellokeita.com/2007/10/16/swfobject-externalinterface-bug-on-ie/
I have not tried this. Here is another solution, http://www.cristalab.com/tips/como-comunicar-flash-y-javascript-en-actionscript-3-c50326l/

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Enhanced Google Analytics: Firefox Plugin

There is new life in the tool that shows change in Google Analytics. A year after releasing our Greasemonkey script, we are pleased to release an updated version of the Enhanced Google Analytics script as a free Firefox Plugin. For those already using the older Greasemonkey script, you can skip ahead to the What's new? and How do I get this plugin? sections of the page. For the rest, you may be wondering: Why does my Google Analytics need change?


Change, and why it is important

When I first started working at Juice Analytics, my boss Zach showed me a part of his daily Google Analytics routine. He would open up the Referring Sites page, glance at all of our 942 referrers. Using his superior intellect and capacity for remembering random urls, Zach would discover interesting deviations in the traffic from sites linking to our blog.

Our top referrers looked more or less similar day to day. Even once you get past the more recognizable top sites such as Twitter and Google, the various somethingblog.com pages, without context, often look a lot like somethingelseblog.com. To top it off, most of the information is not even specifically interesting. Our chartchooser.juiceanalytics.com domain sends us consistent regular referrals, but so what? Day to day, I don't even really care about Google or Twitter unless something changes. With change, I know whether someone has posted something new about me, sending valuable traffic. A good read on the topic is Avinash's rant about "actionable analytics".

Our Firefox plugin is designed to allow analysts to get more action out of what changed in the Referring Sites and Keyword Reports. Here are a couple examples of the plugin in action from our Google Analytics account:


What's new?

Our focus for this release has been to improve functionality, to reduce the barrier to entry for new users, and to allow automatic updates for the plugin. The new version of the script works nearly instantaneously, and the installation involves only two clicks (in contrast to the 7 clicks of the Greasemonkey version). As a Firefox plugin, updates are now automatic and require no reinstall. Keyword sensitivity has been raised to 50% for consistency. As a slight bonus, the design and layout of the form and buttons is now sleeker and the table stands out in a pretty Google blue.

Greasemonkey itself is no longer required for the plugin, but you may want to keep it around for any of the other cool scripts available from the community. If you ever find yourself wishing that something about the web looked different, acted different or had different functionality, there may be a Greasemonkey script to ease your pain.


How do I get this plugin?

First, you need Firefox 2.0+.

If you are a user of the equivalent older Greasemonkey version of this script, you may want to go ahead and uninstall it. Go to Tools=>Greasemonkey=>Manage User Scripts..., select Google Analytics Downloader, and uncheck the Enabled box.

If you never had the script installed, or once you removed it, simply click here to go the mozilla addon site, select the checkbox and click the button. Once installed, navigate to Google Analytics, and go to either the Referring Sites or Keyword pages, and click the blue button.

Happy analyzing!

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

45 comments | Show all comments only the last 5 are shown


March 31, 2010
Burak Tansug said:

Hi,
This is a great plug-in, but I could not find the updated version for Firefox 3.6.


April 12, 2010
Maksym said:

This is unavailable for Firefox 3.6.2. Update it please


May 3, 2010
Nikos Kapsomenakis said:

I would also like to ask you to update this great add on for newer versions of Firefox


May 21, 2010
ChrisM said:

Please add for 3.6.2. Can't wait to use.


June 16, 2010
Tarvinder Gill said:

I had firefox 3.6.2, then downgraded to an older version of firefox to get the plug-in to work.

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Jquery History Plugin With Regular Expressions

Over the past couple months, I have delved into the world of jquery, which, for the uninitiated, is the framework for developing javascript in today's world of web development. Jquery shortens or eliminates many of the more tedious aspects of HTML's dom framework, while allowing elegant access to the fancier effects of javascript. One of the other coolest parts of this framework is the growing number of plugins built by the community.

The plugin that I want to bring up is the history plugin by Klaus Hartl, the original of which can be found here. Javascript usually has problems with the back button, but here it is integrated smoothly, and without forcing the page to do an ugly reload. As an added bonus, the plugin also allows the creation of links that are tied to an internal javascript state. Basically, javascript would now have the abilities of a full-blown 90s style html-only webpage, with the smoothness and efficiency of not requiring any page reloads. A good example of a similar javascript history module in action is Gmail, where the back button works smoothly, and you are able to copy and paste the url to a different window.

My slightly modified version of the script can be found here. This potentially interesting enhancement allows the use of a regular expression when defining the javascript internals for the history plugin. It is useful when the site has additional user-specific variables, such as an id or an object name or number, and the programmer has no desire to explicitly code every possibly imaginable scenario. Regular expressions are very powerful tools.

To use the modified version of the module, use a snippet like this one, substituting a regex for where the history module would normally require a string:

    $.ui.history('add', '(\\d+)/analyze/queries', function(url, pg) {
        set_phrasegroup(pg);
        //do something something
    });

Note the slight irregularity where you need to escape each slash with another slash.

The first parameter, url as passed into the function is the entire string that the user inputed. It would look something like 3/analyze/queries, while pg, any other further passed parameters refer to any of the matched groups within the regex. In this case, we only have one, (\d+), a number.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

2 comments


December 29, 2008
Vimal Shyamji said:

Hi Sal, I found your blog from the Juice Analytics website and wanted to reach out to you because of your obvious passion for jquery. Another client of mine called Blank Slate is using jquery as well (www.widgetthing.me), and the CTO there is also really into it. The purpose of my reaching out to you and Juice was this....I place tech consultants with companies ranging from really small startup's through mid-size companies and Juice looks like the type of company we're usually successful at helping. Anything you can share with me about whether or not Juice ever brings people in for projects and who would handle that process if that did come up?

Thanks in advance....Vimal (617-880-3216)http://www.linkedin.com/myprofile?trk=hb_side_pro


February 3, 2009
lyqwyd said:

note, you are escaping the backslash (\), not slash (/)

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Programmatic Google Trends API

Updated October 21, 2009

Yesterday, Google released an update to their popular Google Trends tool. There are improvements over the previous version, but the biggest new feature is a new shiny button that lets you download all your data in the format of a CSV. This is a very cool enhancement. Where Google Trends was a geeky toy, it now takes the leap to integrate into analysts' reports and with that, edge its way onto managerial desks.

This python module is a quasi-API to make it easier to authenticate into Google Trends for those who want to squeeze the extra level of functionality out of their data. The advantage of programmatic access is that the data can be automatically trended and merged. It can be snuck into a 9:00 AM daily email to the VP of Marketing so that she knows to ramp up Google Adwords campaigns for some specific keyword. Also, by programatically pulling multiple reports, it is possible to create a wealth of data not visible in a single report. Using one keyword as a benchmark to merge multiple reports, we can do a meaningful comparison on tens or hundreds of relevant keywords.

To use the pyGTrends, the quasi-Google-Trends-API, you can download the latest version from github.

Here is an example of the most basic basic report that you can pull down from Google Trends. The connector function needs authentication info, and download_report needs to be passed a list of keywords.

from pyGTrends import pyGTrends

connector = pyGTrends('google username','google password')
connector.download_report(('keyword1', 'keyword2'))
print connector.csv()

You can, however, use pyGTrends to get any slice of data that you can pull down from Google Trends. To see the exact parameters that you should use, go to Google Trends, and navigate to the specific sufficiently-narrow report that you are interested in. Then, right-click on the CSV download, and save the link location. The different parameters should be discernible from the link. The following code downloads a report for banana, bread, and bakery keywords from April 2008, originating from the magnificent nation of Austria, and scaled using fixed scaling (aka the second download link).

connector.download_report(('banana', 'bread', 'bakery'), 
                          date='2008-4', 
                          geo='AT', 
                          scale=1)

By default, the csv() function downloads the main part of the report, but there are a few additional parts stuck to the bottom of the CSV file. If you are interested in those, pass the section parameter to the csv() function. The following will return the Language section.

print connector.csv(section='Language')

Full recommended usage includes using either the csv.reader or csv.DictReader module.

from csv import DictReader
print DictReader(connector.csv().split('\n'))

Here is a snapshot from the new Google Trends to add some eye-candy to the post: Google Trends Eye-Candy

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

39 comments | Show all comments only the last 5 are shown


March 2, 2010
Aloysius Adrian said:

@David
I, also, can not get the connect.csv()

I contacted Mr. Uryasev, and he suggested that I try print connect.raw_data

I did that, but the result/output was : "You must be signed in to export data from Google Trends"

I wonder if you also get that kind of output..


April 13, 2010
Eric Wilson said:

I have the same problem as David and Aloysius. If anyone has overcome this, please let me know.


April 13, 2010
D'Artagnan said:

How do you select multiple years? e.g. 2008 2009 I've tried 2008-2009 and 1/2008 12m but no luck...


June 11, 2010
David Drace said:

Thanks so much for this. I've just launched a site that uses this API to build a U.S. map tracking "flea" search activity, indicating flea prevalence. Have a look: http://banfieldfleafighter.com.

To do this, I set up a cron to poll Google Trends once every morning and write a small CSV file. This file gets parsed by PHP and fed to Flash with every visit to the site.

Aside from the very occasional "Cannot parse GALX out of login page" error, it works like a charm.


July 19, 2010
Sherin seo said:

Great post..It will be really helpful in my reporting structuring !!!Can u just update something about Machros???I am little confused about it!!

For sherin--> www.copperbridgemedia.com ..

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





How Did We Mash Data into Google Analytics?

This post is the code behind how we mashed external data into Google Analytics.

The first step is to yank reference data from the Google Analytics site to reference against Kampyle's data. We specifically want to gather individual names of websites (index.html, /index2.html), and the current selected daterange. The cell references to the website names in the table can be found using a neat Javascript Shell popular among Greasemonkey and Javascript developers. I will not go into detail about the Javascript Shell, but by checking out the various child nodes for the table object we can track down that document.getElementById('f_table_data').childNodes[3].rows[1].cells[1].textContent points at the text in the first cell of the first row. While the syntax looks long, it is just nested HTML in a more elegant programmatic fashion.

For the date, Google Analytics uses a slightly peculiar hybrid system where the date is drawn initially from the URL, but if the date is modified with the java date tool in the upper right hand corner, it uses that instead. From our end, document.getElementById('f_primaryBegin').value and document.getElementById('f_primaryEnd').value are the java date tool values that only start existing if the date tool is used. Pull these two values if they exist, and simply parse the date from the URL otherwise.

The clickable tab we created is essentially the equivalent of a little Greasemonkey button with a few frills that can be created in the standard Greasemonkey fashion. Wherever possible, I use Google-defined layouts for consistency with the site.

Next, we want to send out our reference data to some external server. Greasemonkey has good functionality for pulling data from other sites and servers through the use of the GM_xmlhttpRequest command. A server-end PHP or Django service might be easiest to implement. In this specific example, Kampyle wanted to use the SOAP protocol. While there is an excellent overall SOAP client for javascript by Matteo Casati, this client does not work in a plug and play fashion with Greasemonkey, and needed some modification. For any devoted SOAPers who want to try Greasemonkey, the revised javascript-soap-client code can be found in the attached file. We use the SHA256 encryption function written by Angel Marin and Paul Johnston, but that is accomplished by just copying and pasting the function into our code.

The result comes back in the form of an xml object describing each row in the table, which we parse using native Javascript/Greasemonkey methods, and pop back into the table in the way that we extracted the individual website names. A neat trick here is to call each individual row individually, and not to wait for the data to come back before calling the next row from the server. Separate listeners can wait and insert the data at their leisure. This allows our page to load up faster, and in case there is an error with one data element, it could potentially allow the rest of the rows to load in peace.

You can play around with my code here. This code is released under the BSD License. You won't be able to run the code verbatim without Kampyle's compliance, since they have changed the API calls on their server. However, much of it should be very portable to other data sources.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.

2 comments


September 13, 2008
Gotham said:

This post have great information but I needed a few clarifications. For one of my clients I have usual web analytics info displayed in GA. Additionally the client has call tracking data in its own database. Can I pull that info into GA in a new tab? Your mashup indicates that you added a new tab called "Kampyle", are the names of the table which shows up configurable? (e.g URL, avg grade)


September 16, 2008
Sal Uryasev said:

Hey Gotham,

Yes - as long as you have easy access to the data, you can push any data that you want into Google Analytics. If the data is completely static, you can even add it to the script. Alternatively, you could have a hosted file somewhere. In our case, the data was very dynamic, so we used a server with another web service to fetch the data.

If you click on the picture above, it'll show you the entire table, including column names that I changed around. Essentially, you have the power to change any text that you can select by a mouse. It is just a matter of knowing where to point your code.

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Earlier writing