Technical Notes, References and the sort

What was that issue 4084, back in June 2014?

posted Jun 25, 2014, 3:52 PM by Faustino Rodriguez   [ updated Oct 2, 2014, 11:01 AM ]

Back in June 2014 (this month, when writing this post) Google improved their Drive web hosting service, with some unintended side effects, that we suffered for about two days.

We learnt an important lesson: even a giant like Google can create some "unintended side effects", but when you are ridding his wave, you can trust in a prompt solution, we are not alone.

I have copied below all the notes and updates we publish at that time, just for any future reference.


Temporary Issue Note (as June 12, 2014) updated Jun.16 | Jun.17 | Jun.18 FIXED !!
- There is a new and hopefully temporary problem on Google side, while loading a web page and resources (javascript, css, etc) hosted on Google Drive
- Google Drive is redirecting the Url, adding a prefix Id and removing the parameters in that web page call
- Your map page link is like https://googledrive.com/host/folderID/xsMapping.html?f=mySheet.Data.json
- But, it's converted into this, without the parameter at the end ?f=mySheet.Data.json
https://prefixID.googledrive.com/host/folderID/xsMapping.html
** that's the reason it's loading demo data instead of the user's data **
even though they are called using a secure connection (https), they are blocked as insecure content (http)
- we opened an issue ticket (see link below)
* please, star that issue to get more attention from Google support team (Inline image 1)
apologies for the inconvenience

LATEST update Jun.18 @7:25pm EDT: FIXED, since two (2) hours ago, as reported by Google, working fine since then as confirmed by several users.

** Temporary workaround you can do on your map call, while Google is fixing this issue **
Original map Url: https://googledrive.com/host/folderID/xsMapping.html?f=mySheet.Data.json
Google Issue Url: https://prefixID.googledrive.com/host/folderID/xsMapping.html

Use this Url instead: https://prefixID.googledrive.com/host/folderID/xsMapping.html?f=mySheet.Data.json
(replace prefixID, folderID and mySheet with your own information)
and it should work

* update Jun.18 @9:05am EDT: Still waiting for a fix from Google. See a workaround explained above

* update  Jun.17 @11:50am EDT: Google is working on fixing this issue >> this is Google latest comment #23
"Thank you all for the reports.  After some investigation, it seems that some recent changes that were made to improve Drive web hosting had some unintended side effects that are the cause of these errors. 
These are in the process of being addressed, and should be corrected soon."

* update Jun.17 @11:35am EDT: this issue is back and strong since yesterday

* update Jun.12 @7:20pm EDT: it looks like this issue has been fixed, at least it's working now from my side
Please, submit a feedback (form below) if you are still having any problem

* update Jun.12 @12:20pm EDT: this problem is only happening with the Chrome browser, it is working fine on Mozilla Firefox, IE and pending to check on Mac Safari

GApps Sites, GAS Tracking within your Domain

posted Jan 28, 2013, 8:14 AM by Faustino Rodriguez   [ updated Jan 28, 2013, 8:43 AM ]

To Track Or Not To Track? 
Tracking visitors in your Web site is great for statistics but I would say, do it always Anonymously, in other words, do not collect neither track personal behavior, it's not polite nor completely legal. Particularly if you do it using GA (Google Analytics, see TOS #7 Privacy).

However, there are some circumstances when monitoring user's visits maybe be right and even legal, like when you have a private Google Site just for the users within your domain and you have full disclosure of this tracking and a privacy policy to support it. It's like having your own Intranet in the Cloud. In any case, consult your legal adviser to be safe.

Now, let's deal with the technicalities around monitoring user's visitors within your domain site using Google Apps Script, step by step simplified:
  • Have a Google Site just shared within your domain, so users have to be logged in with an account in your domain to have access to this website.
  • Have a Google Analytics Property ID that you want to associate just with this site monitoring, like UA-12345678-1
  • Within this Site go More > Manage site > Apps scripts > Add new script, with the following content
function doGet() {
  var utmUrl = gaTrack("UA-12345678-1");
  return HtmlService.createHtmlOutput("Privacy Note: This page is monitored for statistics and internal use.");
}
function gaTrack(propertyId, path) {
  try {
    var utmGifLocation = "http://www.google-analytics.com/__utm.gif";
    var path = SitesApp.getActivePage().getName();
    var utmUrl = utmGifLocation + "?" +
        "utmwv=4.4sa" +
        "&utmn=" +  (new Date().getTime())+ //unique - cache buster
        "&utmhn=" + Session.getUser().getEmail().split("@")[0] +
        "&utmp=" + encodeURIComponent(path) + 
        "&utmac=" + propertyId +
        "&utmcc=__utma%3D999.999.999.999.999.1%3B" +
        "&utmvid=" + Math.random() +
        "&utmip=" + "-"; // "&utmip=" + "-"
    var fetch = UrlFetchApp.fetch(utmUrl);
    return utmUrl;
  } catch (e) {
    return "Error on utmUrl" + utmUrl;
  }
}
  • Save the script and name it gaTracking (or any other name)
  • Follow this sequence to publish the script: File > Manage version > write some description and save new version, then Publish > Deploy as web app... > Select the project version > Execute as user accessing the web app > Access anyone within your domain > Deploy
  • Go back to your website and select a edit the first page you want to monitor > at the end of that page > Insert > Apps Script Gadget > Select (✔) the script you just published > Select > Uncheck border and title > Set the Height > Save
  • About the Gadget Height: at least you would need a main page with that gadget height about 500 pixel to allow users on their first visit to authorize the script to run the Sites service
  • Then insert the same Apps Script Gadget to any other pages you want to monitor
  • To check how your users are visiting those pages go to Google Analytics and select the Property ID you have assigned to the script and look under > Reporting > Content > Site Content > All Pages > Sort by Page > Add a Secondary dimension > Content > Hostname >> and you would see your users, site pages and pageviews there
I believe, that's it
Share your comments and question with g+1 below, I will thank you for that ;)

GAS Doclist find and getFiles for filtering

posted Oct 18, 2012, 6:35 PM by Faustino Rodriguez

When writing an App using Google Apps Script (that's GAS;) I had to provide some documents list within a folder with filtering functionality. So when the user enter a search string the App would list all documents within the App folder that matched that criteria, being within title or the actual content.

What I have learnt so far?

1. Google doesn't search within the actual documents but in their indexes, what makes a lot of sense Google-wise, however you have to be prepare for some delay for recent documents to appear on that search (minutes, hours, maybe more?). In the mean time you better remember what was about your latest documents.

2. Google will search within the revisions history of your documents, so it will show documents that match your search even if they are not currently containing that string criteria but they had in the past, what is good, very good.

3. My first "naive" approach to search was using always the function find like this line of code below
qDocsFolder.find(e.parameter.filterDocs)
However, I ended finding out that searching for an empty string will take a lot of time (many seconds I mean)
I had to change the approach using getFiles function for empty string instead, like below few more code lines
var qDocsFolder = DocsList.getFolder(e.parameter.qDocsFolderPath_);
var allDocs = (e.parameter.filterDocs) ? qDocsFolder.find(e.parameter.filterDocs) : qDocsFolder.getFiles();

4. When doing as above I found out (at least in my case) that find function will return documents sorted by "last modified date, reverse" while getFiles function would sorted by "document name, normal". Just to get more consistency and having all sorted by "last modified date, reverse", as it was the requirement to show the more recent changes first, I introduced an intermediate array to sort as below
var qDocsFolder = DocsList.getFolder(e.parameter.qDocsFolderPath_);
var allDocs = (e.parameter.filterDocs) ? qDocsFolder.find(e.parameter.filterDocs) : qDocsFolder.getFiles();
var allDocs3Array = [];
for (var i in allDocs) allDocs3Array.push([allDocs[i].getName(), allDocs[i].getId(), allDocs[i].getLastUpdated()]);
allDocs3Array.sort(function(a,b){return b[2] - a[2];});
In this case we get the documents list sorted by getLastUpdated reverse and the first two elements of this array are ready to be added as items in a list box.

ps. I would update this post if anything else important comes to my attention on this subject.

Cloud SQL and Datastore

posted Jul 11, 2012, 7:01 AM by Faustino Rodriguez   [ updated Jul 11, 2012, 7:20 AM ]


When working on Google Apps Engine you have a choice of Databases
  • standard MySQL coded Cloud SQL, or
  • schema-less NoSQL coded Datastore
Although "the best tool is the one you master" having regular skills in both approaches would give you plenty of choice when starting a new project.
Here is a video presentation from Google IO 2012 on the subject that shows some confrontation towards reconciliation at the end. The presentation goes over a few topics on both databases like Queries, Transactions, Consistency, Scalability, Management and Schema.

In my view
  1. If you already have a project or even just a design SQL based, the right choice might be Cloud SQL
  2. For a very simple & small App or for the very complex & large project, Cloudstore might be the right choice
  3. For a standard App specially designed for your Company Cloud SQL would be my recommendation
Other than that we should look at cost while running an App using either one

ps. more choices as usual > look for Google Cloud Storage and ScriptDb JSON Database.

Gmail signatures (standard, html, canned)

posted Jul 2, 2012, 9:46 AM by Faustino Rodriguez   [ updated Jul 2, 2012, 10:22 AM ]

Quick reference to
- standard signature
go Gmail settings > general: signature and you would find there a simple HTML editor to create your standard / default signature, to be included on each of your email, so keep it simple not to bother your audience to much
- trying some html and image

- getting fancy with canned responses

More Gmail with Labs

posted Jun 30, 2012, 7:51 PM by Faustino Rodriguez   [ updated Jul 2, 2012, 10:18 AM ]

While using Gmail for your domain within Google Apps for Business, you can improve the functionality with a few extras included in Labs. Some of them would be just "crazy experimental stuff", however the some would be default features at some point.
Go Settings > Labs and enable the following features for  better experience: 
  • Apps Search: Gmail searches including docs, chat, etc... > No longer in Labs, but included as standard feature through Domain settings ... 
  • Canned Responses: Email for the truly lazy. Save and then send your common messages using a button next to the compose form. Also automatically send emails using filters. Good for extra fancy signatures. 
  • Inserting Images: Allows you to insert images into a message body. You can upload and insert image files in your computer, or insert images by URLs. This lab will not work if you have offline enabled. 
  • Message Sneak Peek: Peek into a conversation without opening it by right-clicking on a message in your inbox. 
  • Signature tweaks: Places your signature before the quoted text in a reply, and removes the "--" line that appears before signatures. 
There are many others for you to try, we have settled for these few extras.

1-6 of 6