I owned a google form, how can I get the js script of it?
I click the Script Editor but there is no corresponding js I can find.
I have already searched on internet but no expected answers.
--
update on 20/08/2017
Assume that I owned a form like this :
Sample Form.
How can I get the corresponding google script of this form?
i.e.,
function myFunction() {
// Create a new form, then add a checkbox question, a multiple choice question,
// a page break, then a date question and a grid of questions.
var form = FormApp.create('Sample Form');
var sect1 = form.addSectionHeaderItem();
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish')]);
var item2 = form.addMultipleChoiceItem().setTitle('Do you prefer cats or dogs?');
// .setChoiceValues(['Cats','Dogs'])
// .showOtherOption(true);
var sect2 = form.addSectionHeaderItem();
form.addPageBreakItem().setTitle('Getting to know you');
form.addDateItem().setTitle('When were you born?');
var sect3 = form.addSectionHeaderItem();
var break2 = form.addPageBreakItem().setTitle('Getting to know you 2');
var choice1 = item2.createChoice('cat', FormApp.PageNavigationType.CONTINUE);
var choice2 = item2.createChoice('dog', break2);
item2.setChoices([choice1, choice2]);
form.addGridItem().setTitle('Rate your interests').setRows(['Cars', 'Computers', 'Celebrities']).setColumns(['Boring', 'So-so', 'Interesting']);
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
}
Google Script Editor is a way that Google allows people to make their forms (and many other Google services) more flexible and customizable. You can even create Add-ons using Google Scripts. But there is not such thing as a default user script for each form; all forms begin with no user Google Scripts at all and it is up to you to add some more functionality by writing some new scripts.
Now, if you mean to get the javascript source of that form, then you can use Developer Tools in Chrome (F12 key in Windows) and go to sources, there you'll see all the cripts that Google uses for the forms:
And if you left click the form and view the source of it, you'll see some more small script blocks mostly related to the data that the Google Form has:
<script>_docs_flag_initialData={ ....
<script>;this.gbar_={CONFIG:[[[0,"www.gstatic.com", ....
<script type="text/javascript">var FB_PUBLIC_LOAD_DATA_ = [null,[null, ....
Another approach can be to create a html form yourself and send a request to a Google Apps Script Web app. See this example if you want to try it out: https://gist.github.com/mhawksey/1276293
Regards, Peter
Related
I would like to create a custom plugin for tracking events in my JavaScript Application using Google Analytics Measurement Tool (GA MT), but I am a newbie and not sure how to write such plugin.
My idea about the plugin:
it should have defined all types of events I am going to track (i.e. starting of an application, button clicked, 1st, 2nd, ... slide entered, etc)
if I understand how GA MT works correctly, I will need to specify an event hit for each custom event (see more)
part of the hit parameters (url) is shared (such as version, client ID, tracking ID...)
the other part of the url is custom, so I will store the differences in various functions inside of the plugin
these functions will be later called i.e. on button clicked, on goToNextSlide etc, which will send a hit to GA.
This is an example of my plugin:
(function( $ ) {
var $_document = $(document);
// Shared hit parameters
var hit = 'https://www.google-analytics.com/collect?';
hit += 'v=1'; // Version.
hit += '&t=pageview'; // Pageview hit type.
hit += '&tid=UA-XXXXXX-Y'; // Tracking ID / Property ID.
hit += '&cid=555'; // Client ID.
/* Application opened */
function gacAppOpened() {
console.log('gacAppOpened');
hit += '&dp=%2Fslide-1'; // Page.
httpGetRequest(hit);
}
/* Slide-2 entered */
function gacSlide2() {
console.log('gacSlide2');
hit += '&dp=%2Fslide-2'; // Page.
httpGetRequest(hit);
}
function httpGetRequest( theUrl )
{
var req = new XMLHttpRequest();
req.open("POST", theUrl, true);
req.send(null);
}
}( jQuery ));
This is how I load the plugin (gaCustom.js) and my common JS file (app.js)
<script src="js/gaCustom.js"></script>
<script src="js/app.js"></script>
When trying to reach to my function from inside app.js, I got error (not a function)
goToDefault: function() { // loads first page of my app,
// a hit should be sent to GA about app started
...
gacAppOpened();
... // render template
},
So I am wrong somehow in defining the plugin and using it. I also tried few other attempts, but all of them failed.
I would appreciate to hear whether my approach is good or wrong and what to improve as I am a newbie and would like to do this correctly.
I just wrote my first bookmarklet. It is simple js code which takes the current page's URL and does a POST request to submit it to another page.
The problem is that I need to share this on a blogging platform (quora.com) that does not allow HTML. Thus, I need to post a link to my bookmarklet on a different website and provide a link to that. I'd like to be able to provide a single link that folks can drag to their bookmarks bar.
This is the bookmarklet code.
javascript:(function() {
var msg = window.jQuery.ajax({url:'https://www.quora.com/api/logged_in_user',async:false,type:'GET'});
var username = undefined;
if (msg) {
username = window.jQuery.parseJSON(msg.responseText.replace('while(1);',''));
window.jQuery.post('https://my-website',
{'answer_1':window.location.href,'submitter':username.name});
alert (username.name + ' nominates ' + window.location.href);
}})();
I have a problem with the class Session in Google Apps Scripts
I wrote a script that records the date and user who edits a sheet in a spreadsheet. It works good with my test page, but when I put it in another spreadsheet (a copy named like "test") it does not work!! I have 8 Spreadsheets with the same number of sheets, all named similar, and the script only works in one of the spreadsheets (and test). This is the script:
function onEdit(event)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Last Session record
var actSht = event.source.getSheetByName("somepage")
var actRng = event.source.getActiveRange();
var lastCell0 = actSht.getRange(2,16);
var lastCell1 = actSht.getRange(2,17);
var date = Utilities.formatDate(new Date(), "GMT-6", "dd/MM/yyyy HH:mm");
var r= actSht.getActiveCell().getRow();
lastCell0.setValue("Date_Mod");
lastCell1.setValue("user");
if(r=='3'){
actSht.getRange(r,17).setValue(Session.getEffectiveUser());
actSht.getRange(r,16).setValue(date);
}
if(r=='4'){
actSht.getRange(r,17).setValue(Session.getEffectiveUser());
actSht.getRange(r,16).setValue(date);
}
}
This is the same code for two spreadsheets, in one it works OK, in the other it does not work.
How do I fix this?
It is most likely a security issue and Session calls are supposed to be avoided in simple triggers due to simple triggers limitations (look at https://developers.google.com/apps-script/guides/triggers/#restrictions, especially in regard to the very vague 5th bullet point - "They may or may not be able to determine the identity of current the user" (mistake on page) and where the link sends you back to the session page). In your case I wonder whether it worked only for the users who shared your domain name.
If you look at https://developers.google.com/apps-script/reference/base/session#getEffectiveUser() there is no reference for simple triggers (which for me is suspicious already) but the statement in regard to installable triggers tells me that it should probably not be used in simple ones.
I just went through a similar exercise myself where both getActiveUser and getEffectiveUser were returning blank when the domain of the script owner did not match the domain of the person who launched the script (in other words this happens when someone shares the script outside the domain and run it under a different username such as their personal Google account). I therefore created an installable trigger instead that calls getEffectiveUser and it works now (note that if you define your installable trigger programmatically rather than through Resources->Current project's triggers make sure the trigger function is in the invoking script file).
Hope this helps.
I have a site which shows the weather for the next three days of a previously specified city (default city or city searched using a form) --> http://agustin-suarez.com/demos/yield/index.html
I use the API of OpenWeatherMap.org to do so. I am also using Google Tag Manager to send some events to Google Analytics which save the results obtained in the website. This is the code for the Macro (custom html tag):
<script>
(function($) {
$(window).bind("load", function() {
var climaMañana = document.getElementById("reservar1Clima").value;
var precioMañana = document.getElementById("reservar1Precio").value;
var climaPasadoMañana = document.getElementById("reservar2Clima").value;
var precioPasadoMañana = document.getElementById("reservar2Precio").value;
var climaDosDias = document.getElementById("reservar3Clima").value;
var precioDosDias = document.getElementById("reservar3Precio").value;
dataLayer.push({'event': 'climaMañana', 'eventLabelMañana': climaMañana, 'eventValueMañana': precioMañana});
dataLayer.push({'event': 'climaPasadoMañana', 'eventLabelPasadoMañana': climaPasadoMañana, 'eventValuePasadoMañana': precioPasadoMañana});
dataLayer.push({'event': 'climaDosDias', 'eventLabelDosDias': climaDosDias, 'eventValueDosDias': precioDosDias});
});
})(jQuery);
</script>
It works really good 90% of the time, but if the API spends more time than usual to send the response, Google Tag Manager is sending those events anyway with blank values for the variables, which is not optimal for keeping data quality in Google Analytics.
Any suggestion for making Google Tag Manager to wait until all variables are populated?
There's a company that has a local website that provides a list of job search opportunities.
The website is something similar to Indeed.com! Here is the link. -
http://www.akronworks.com/
The entire website is in ASP.NET! C#, SQL, HTML, CSS.
Is there a link or a way to use Indeed API? Or a way to find the basic "Search Function Structure Template? I'm creating an application that needs a basic local job search function.
Everything else can be written in the SQL Database.
I found something that was written in Javascript.
Heres the code -
function indeed_clk(a,sig) { var hr = a.href; var si = hr.indexOf('&jsa='); if (si > 0) return; var jsh = hr + '&jsa=' + sig; if ( jsh.indexOf('&inchal') == -1 ) jsh += '&inchal=apiresults'; a.href = jsh; }function init(){(new Image()).src=document.location.protocol+'//gdc.indeed.com/rpc/apilog?a=apiresults';}if (window.addEventListener){window.addEventListener('load', init, false);}else if (window.attachEvent){window.attachEvent('onload', init);}
I found this inside of there source-code. I'm wondering how all of the positions get displayed. How many databases do you think you this site would take to operate? All of the positions have to be store in multiple databases right?
Is there any open-source code that could provide the same functionality?
Thanks - Blake
Indeed does have an api you can use their site link (you will need to create a developer account):
http://www.indeed.com/jsp/apiinfo.jsp
and additional info, how to's, etc. you can go to:
http://www.programmableweb.com/api/indeed