Custom HTML5 Geolocation Prompt - html

As I am testing out one of the HTML5 features - geolocation for my project,
I realized that users can close the prompt without allowing or denying it,
that defeats the whole purpose of the prompt.
And because in my project I want to dynamically display data to users depending on user's location, this can't be done, simply because without knowing user's response,
it doesn't trigger any of the two callbacks - success / error.
so I started searching to see if there's any solution to this,
and a lot of suggestions to this is to set timeout,
I tried and everything works perfectly.
However, one small flaw here is tho, by the time it hits the timeout expiration,
all the data are already displayed, and when i say all, i mean EVERYTHING,
because there's no location detected.
So I came up with two solutions that might work,
1) create a custom geolocation prompt that forces users to allow/deny location to be shared,
and pass the response to browser to set the location preference
2) pause page-load (stop stuff from being rendered) and wait till it hits the timeout expiration or it gets response from users
Does anyone have any idea how to implement one of these two solutions?
PS: sorry if this isn't unclear to you, i know my english sucks, but I can explain in more details.
Thanks guys!

You shouldn't be able to use a custom Geolocation prompt if your project is browser based, because malicious developers could use the method to trick the user. Also, since the Geolocation API is an asynchronous event, it's going to continue loading the rest of the page while it waits.
What I recommend is to use a conditional statement instead with an else clause. This way, your script functions should only execute after location has been shared, and you have a fall back on what should happen if no geolocation information is provided (which I highly recommend as situations will occur when the data isn't provided).
Example of the conditional statement to check for geolocation information using JS:
if (navigator.geolocation) {
// code to run if there is geolocation information
}
else{
// code to run if no geolocation info is given to the browser
}

Related

Lower the timeout for urlFetchApp.fetch function

I need to test an external URL, and if it fails, fail faster than the default (3 minutes, apparently).
Numerous posts on several forums, including an "enhancement request" to Google, that have gone unanswered, so I thought I'd try here again.
Has anyone conjured a way to do this?
In my particular case, I don't care about getting any content back; my task is simply to test the URL and see if the remote server is alive and responds at all. So, maybe is there a way to change the parameters or headers in the request, to make it "reply instantly or fail quickly" ? For me, maybe ~30 seconds would be fast enough for failures.
Cross posted here:
https://www.reddit.com/r/GoogleAppsScript/comments/iqh9dl/how_to_change_lower_the_timeout_for/
Consideration
In Apps Script the UrlFetchApp.fetch method doesn't accept any callback nor custom timeout parameter. Unlike it does for example in Google Cloud.
Due to the synchronous nature of Apps Script is impossible to wrap the function result in a timeout either.
This feature has been requested
The feature of adding a custom timeout parameter has been requested so feel free to star the issue in order to increase its visibility. Here is the link.

What would happen if # of events exceeds 500 on Firebase Analytics?

I have been using Firebase Analytics for my apps and I like it.
Currently I have 300 events set up on one of my apps.
I learned that the max number of events we can have is 500.
What would happen if # of events exceeds 500 on Firebase Analytics?
Would it just stop logging new event? (501st event)
Or is there any better way to avoid it?
I will appreciate your advice!
Extra events are dropped. A firebase_error event is logged with a firebase_error parameter which indicates the error code. See this documentation for more information.
There's no other way to avoid it, but to manage your event logging implementation properly. Note that event in Google Analytics for Firebase is equivalent to the user's interaction within your app.
I would not suggest to create or log an event with incremental index, prefix or suffix in the name. You may also want to use the event parameter.
For example, you have a login page (with authentication methods of using Facebook, Google or Username/Password) and you'd like to track what is the most commonly used by the users. With this, you could log a custom event with the name of "user_login" and a parameter or login_method. After this, add the parameter in the custom parameter reporting to see the counts.
Hope this helps :)
Just for clarification because this confused us and there is no clear documentation on this:
The 500 events limit is per user per day and not per project globally. So events are only dropped after a single user uses more than 500 unique events per day, everyone else will continue to log events.
So if you have more than 500 events thats fine, you dont need to replace them you just need to remove them from your current app from being logged and use new ones, then this user will never use the old events and it does not count towards his 500 event limit.

Windows phone 8 push notification how to use ChannelUpdatedUri to detect channel updates

I would like to know what is the clean & correct way to notify my WP8 app that the ChannelUri has changed?
I read that i need to handle this in the ChannelUpdatedUri method. But i have a few queries here. Doesn't this require my app to be running all the time?
Second query is suppose i use ChannelUpdatedUri to listen for changes to the Uri. If there is a change will the app be notified as soon as it launches? Or will it be notified at a later time?
The trouble is if the app is not notified on launch then there is a possibility that it may re-register for a new channel uri before ChannelUpdatedUri is invoked. Isnt it?
Please help!
You'll only get notified of a change in the ChannelUri when you have the listener attached and the app running.
The best approach is to always check for the current Uri and pass it to the server when the app starts. You could leave the listener attached for the lifetime of your app and get a new one if it's lost while the app is running but in reality it's far more likely that the channel will be dropped/disconnected when the phone isn't in use.
There is, of course, the scenario where a channelUri may expire when the app isn't in use but the utility of the app is primarily around sending notifications. Obviously you need the user to restart the app to get a new connection but you can't tell them to restart the app.
This is a generic problem: how do you tell someone that you can't talk to them?
The reality of this situation is that if you really need to tell someone to launch the app again you'll need another way to do it.
Unfortunately, it's not possible to get an updated channelUri from a background agent, but you could query your backend to see if you need one and then raise a toast to the user to prompt them to reopen the app. Or you could just update the tile from the agent when this happens.
Alternatively you'll need to send them the prompt in another way (e.g. email or SMS?) but this is reliant on you capturing and securely storing these details.
There is no perfect solution to this scenario other than creating an app that the user opens regularly regardless of whether there are notifications or not and simply having the notifications as an extra feature.

Determine when user leaves WinJS app

I'm building some very basic analytics for in-house WinJS apps. Take this to mean that a 3rd-party analytics solution would both overkill and/or unworkable and/or against the 3rd-party providers terms of use as they generally disallow capturing personally identifiable information about the user, and in this case that is a business requirement.
The thing I'm trying to do is determine how much time is spent in multiple apps, and in areas within certain areas of the app. For this I obviously need to know when they enter and leave.
All the documentation I've found says to use the WinJS.Application.oncheckpoint event or the Windows.UI.WebUI.WebUIApplication.onsuspending event, which really seem to be two access points into the same basic concept. The problem is this doesn't accurately reflect when the user leaves the app! Suspend seems to happen only after the user has switched to another app, plus about 10 seconds ...... if the system feels like it.
If the user simply hits the Windows key to go out to the Start Screen and just sits there, the app continues to run indefinitely (calls to setInterval are able to affect state) even though the app cannot be seen!
I understand this is a bit of an edge case, but is there any more reliable way to tell when the user can't see the app, for lack of a better definition?
Notes:
I did look at the Cordova 2.7 code for Windows 8 and they are using the checkpoint event to drive the Cordova pause event.
App Visibility section on Application lifecycle seem to address this. This means registering for `msvisibilitychange' event, to know when user moved away and moved back to your app.
default.js:
document.addEventListener('msvisibilitychange', function ()
{
console.log('visibility changed');
console.log(document.visibilityState); // 'hidden' or 'visible'
});
In addition, suspending, resuming and activated events also needs to be handled.
default.js:
Windows.UI.WebUI.WebUIApplication.onsuspending = function ()
{
console.log('suspending');
}
Windows.UI.WebUI.WebUIApplication.onresuming= function ()
{
console.log('resuming');
}
Needless to say, that nuance of ordering, and/or event being absent cases needs to be handled. For example - if the user moves away and comes back quickly, visibilitychange event will be received. whereas if user does not come back suspending event may come after some time. if the app is not terminated, it may be followed by resuming event. otherwise, activated event.
regards spending time on specific pages, page ready and unload method should work. unload() will not get called if the app is suspended or terminated.
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/visibilitychange
Use the visibility change event to recognize when the user can no longer see the app.

UiApp: Persistent login for non-gmail users

I am attempting to implement a Google Apps Script web service which requires users to log in using an account set up on our system.
The users will not necessarily have a gmail account, and should not be required to create one.
The web service must run using as the script owner, as it is necessary for it to be able to write to a spreadsheet and other resources which do not have shared write permission.
I have managed to implement the login screen, with reasonably strong security -- but the problem I encounter now is that users must log back in every time they visit, and even if they hit the refresh button.
Any ideas on how to implement this?
Is there some way to store a cookie in the users browser, containing a session id?
Or is there some other method which can work?
Thanks in advance!
Josh
This is a very old post but as there is a solution, I think it is better to show it to help people with a similar need
Hi Josh,
I have developed such a system and there is indeed a way to do this.
You can indeed develop a cookie like system that is using the PrivateCache class: CacheService.getPrivateCache().
It works if the user reload the page or close it.
However with this solution when you close your browser it will not be possible to retrieve the information anymore.
Here are the functions that I use to prevent the problem you have underlined
Feel free to adapt them
function getCookie(){
var cache=CacheService.getPrivateCache();
var cached=cache.get("UserCookie");
if(cached!=null){
return Utilities.jsonParse(cached);
}
return -1;
}
function createCookie(data){
var cache=CacheService.getPrivateCache();
cache.put("UserCookie",Utilities.jsonStringify(data),1800);
}
function removeCookie(){
var cache=CacheService.getPrivateCache();
cache.remove("UserCookie");
}
Another way would be to use UserProperties. In this case it will work even if you close your browser... I just tried it
the functions to use are therefore:
function getCookie(){
var cached=UserProperties.getProperty('UserCookie');
if(cached!=null){
return Utilities.jsonParse(cached);
}
return -1;
}
function createCookie(data){
UserProperties.setProperty('UserCookie',Utilities.jsonStringify(data));
}
function removeCookie(){
UserProperties.deleteProperty("UserCookie");
}
I hope it will help anyone...
Cheers
Nicolas
Persistent login are not possible with Apps Script as Apps Script can not interact with browser objects like cookies etc. Apps Script is intended to work only with Google Accounts.