views:

328

answers:

1

I figured out how to create a bookmarklet for Google Analytics that opened to immediately show only today's stats. I wanted to make a Google Chrome application shortcut for this to go along side my other Google Apps shortcuts, but the first problem is that it only creates an application with the current url, which displays today's info and of course will display yesterday's info tomorrow. I figured I'd edit the target to the shortcut and replace the url with the javascript I had. The second problem is the line of script is too long. Window's shortcuts target paths can only hold 290 characters or something like that. The path to Chrome as well as the script went past that.

What are my options at this point? I've scoured the web and wasted way too much time for such a small piece of my life, but I'd like to figure it out.

I know jimmy-squat about programming. I can sort of edit javascript, but not really write it. I used the YUI Compressor to try and shrink it down, but it didn't change much. I also tried using a url shortener, but they all add the http:// prefix and that screwed it all up. I read I could point to a bat file in the shortcut target, but couldn't figure out how to do that either... plus I figured there was an easier way to do this that didn't require any minor hacking, which I'd like to avoid.

I was easily able to bookmark the site in Chrome and replace the url with the javascript and it works fine, and that was half my goal. But I really would like to have this as a Windows shortcut and behave in the exact same way the other apps work because they remember the previous window size.

Any suggestions on an easy solution?

Here's the bookmarklet's script -

javascript:var d=new Date();if(d.getMonth()<10){var pad='0';};var t=''+d.getFullYear()+(pad+(d.getMonth()+1))+d.getDate();location.href='https://www.google.com/analytics/reporting/dashboard?id=HIDDENID&amp;pdr='+t+'-'+t+'&amp;cmp=average'

Also here's the path to different but pretty similar application shortcut from Chrome -

"C:\Documents and Settings\USERPROFILE\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" --app=http://docs.google.com/a/MYGOOGLEAPPSDOMAIN/
+2  A: 

Why not create a local .html file containing this:

<script type="text/javascript">
  var d=new Date();
  if(d.getMonth()<10){
   var pad='0';
  }
  var t=''+d.getFullYear()+(pad+(d.getMonth()+1))+d.getDate();  
  location.href='https://www.google.com/analytics/reporting/dashboard?id=HIDDENID&amp;pdr='+t+'-'+t+'&amp;cmp=average'
</script>

Then you can just use that as your "shortcut".

The %AppData% may help you get a few more characters out of the shortcut as well. If running chrome.exe from the command line is resulting in a different type of window being opened than double clicking the HTML file, you may need to point chrome.exe at the workaround.html

%AppData%\Google\Chrome\Application\chrome.exe --app=file:///c/googleworkaround.html

Also, manually compressing some of your logic a bit resulted in this 268 character code golf which may or may not work for you.

%AppData%\Google\Chrome\Application\chrome.exe --app=javascript:var d=new Date(),t=[d.getFullYear(),d.getMonth()<9?'0':'',d.getMonth()+1,d.getDate()].join('');location.href='https://www.google.com/analytics/reporting/dashboard?id=HIDDENID&amp;pdr='+t+'-'+t+'&amp;cmp=average';
gnarf
Wow, that didn't even cross my mind and worked perfectly. The only slight issue I have is that it opens up in a new tab in Chrome's browser and now in a stand alone - no address bar - window.
@paul - Can you post what your script is actually doing? I might be able to see the way around that.
gnarf
I updated it in my original post
Check the updates - some of these things may work for you.
gnarf
Wow, the html shortcut pointing to Chrome is what worked. I struggled a bit because I didn't understand the way you pointed to the file location, as well as the %AppData%, so I just wrote it out as it normally would be and it worked perfectly. Stand-alone window, that opens in the same size and location each time and everything. Thank you so much. I really appreciate you taking the time.The last option came up 20 characters short, so I guess I was wrong about the 290.
%AppData% is a environment variable that should be set to "C:\Documents and Settings\USERPROFILE\Local Settings\Application Data" (i think) - not really a windows guy
gnarf