SAPUI5 Logout Event with Javascript - javascript

I am currently working on a SAP XS application. Using the provided API, I want to log off my user on the website. Im totally new on Javascript to please dont mind the probable ease of my question.
The API (https://sapui5.hana.ondemand.com/sdk/docs/api/symbols/sap.ui.commons.ApplicationHeader.html#event:logoff) provides the method "fireLogoff". But before that I have to add "attachLogoff" to the applicationheader in my application right?
My faulty method looks like this:
oAppHeader.attachLogoff(function logout(oEvent) {this.fireLogOff();});
Thank you a lot for helping a noob in this matter.

fireLogOff calls a function assigned to logOff. So you need to write your own code for SAP HANA API that makes user to log off. Or you can just close browser tab:
oAppHeader.attachLogoff(function(){window.close();});

Related

Code in Google Tag Manager does not working

I have a test tasks and 2 from 3 I've done.
But this one I don't understand how and what I need to do?!
I managed to find syntax error:
At first should be:
...function someFunctionName() {...}
or
(function() {...})()
...second it's anonymous function...
TASK:
This script is executed in GTM and implemented in Google analytics by custom Task.
The script sends information about user behavior to Optimozg server and then to Bigquery (bq.php file processes and forwards data). Optimozg server data is coming in correctly, but the data in Google Analytics does not reach.
What is the reason?
How do you fix it?
Hint:
(test the code on your site instance with GTM)
function(){return function(tracker){if("undefined"===typeof tracker.get("BigQueryStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}
return a}
function e(c){var a="https://test.optimozg.com/bq/bq-test.php";c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}
return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),c)}catch(g){}}
if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials" in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}
return a||d(c)}}}();tracker.set("sendHitTask",function(d){h.send(d.get("hitPayload"));tracker.set("BigQueryStreaming",!0)})}}}
Not sure why JS devs should know anything about GTM. They typically don't go there.
But yes, to understand how to use the given code properly, just read this article: https://www.simoahava.com/analytics/customtask-the-guide/ it describes what custom tasks are and how to use them.
Ok, so first make a GTM account. Deploy the GTM code on your site. May as well use a local site. Or, rather, have the GTM code being injected by a local extension to a random site that doesn't have GTM yet. Or maybe use a redirector extension to redirect the request for their GTM to yours, up to you.
After that, you just make a tag in GTM that would send a Universal Analytics pageview. GA4 decided not to bother with custom tasks, unfortunately, so UA only. Then you make a trigger on pageview. You assign the trigger to the tag. Don't forget to publish the workspace at least once for it to be testable. Then you preview. Preview is a CTA in GTM in top right corner, near the publish. Basically a neat GTM debugger. Enter the site where you have your GTM snippet deployed/injected. Make sure preview sees your tag firing on page load. That would mean you did the preparation correctly.
We're doing the Hint section here, by the way. Now you need to make a custom javascript variable in GTM, paste the code snippet as is in there. The reason why it wants the code in an anonymous function is because it will run it as a closure on it's own. So they kinda remove the need of the extra ()(). It's mostly done for people who don't know JS, so don't be surprised.
Ok, you've made the CJS var, now go to your tag, and set your customTag exactly as Simo shows in his article:
Good, now publish your container, go to the site where you have it deployed, open the network tab and reload the page.
Inspect the calls to the BQ and Optimozg endpoints. Now what they ask is, I believe, why the original call that is meant to be sent by the tag is not being send. So if you remove the setting of the customTask, then publish and reload the page, you should see a request to the collect endpoint, which is the GA's endpoint for data tracking. If you re-add the customTask code, it will prevent the normal tag's functionality from execution, so no collect call.
What they want to hear from you is how to make the tag fire the original event alongside their optimozg and bq calls.
Most likely, the answer is pretty simple and elegant, but requires a lot of debugging to reach to. Reading Simo's article will help understanding the significance of setting various tasks.
Uh, ok, I didn't mean to really debug it, but it looks like I found the bug. It's in the var f = tracker.get("sendHitTask") It's being used to store the original sendHitTask function, but it never gets used. Why is that? Basically, you just need to call the function in the new sendHitTask function that you set in the last line. I'm not going to debug it in my GTM, but I'm pretty sure that's the issue. It's kinda begging to be found there.
Also, this is not quite a junior JS dev task. It's a senior tracking implementation task. Basically, about $110/hr in Canada and US. Junior JS devs are around $35/hr, I guess. They're just trying to save money, heh. I was thinking of hiring junior JS devs instead of tracking implementators too, but it's hard to teach how data analysis works in all the different tools.

What is the recommended way to persist the data in background task? [UWP/W/WP apps]

The question is quite simple, but I seriously couldn't find any sample that would demonstrate something I'm trying to achieve, maybe it's me who is didn't get the concept of background tasks in uwp applications (or windows / windows phone 8).
I'm creating an application that is polling some data (traffic incidents) and would like to be able to notify the user about the closes ones even if he is not using the application. So I reckon I would use the background task. (I hope I get that part right).
So in the background task, which I've set to run on timer of 15 minutes, under the condition of "InternetAvailable", I fetch the data asynchronously and once it's done, I'm completing the deferral object as it's required. All works ok.
The question is, what object shall I use in order to persist the data so I could read the data once the application is opened?
I've tried the WinJS.Application.sessionState but that gets lost once the application is ready (opened).
I've tried the Windows.Storage.ApplicationData.current.localSettings but it says there is a type mismatch, apparently I'm trying to put in there the object, if String is expected (I reckon)...
So does anyone know what is the best practice here ?
Thank you
You have full acess to the WinRT API, so you can write a file (and read the same file once the application is opened):
function saveData(dataObj) {
var applicationData = Windows.Storage.ApplicationData.current;
var localFolder = applicationData.localFolder;
return localFolder.createFileAsync("dataFile.txt", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (sampleFile) {
return Windows.Storage.FileIO.writeTextAsync(sampleFile, JSON.stringify(dataObj));
});
}

How can I write a script to automatically walk through a process like my user would?

I have some valuable processes on my site that I'd like to track regularly to make sure they are working. I wrote some javascript that will run the actions if the starting page contains a particular parameter, but I can't figure out how to properly execute the script without opening the page in a browser.
My best guess is I need some sort of chron driven bot for this, but I don't even know where I should begin with that and haven't found anything in my searching. I tried a cURL request, but it doesn't seem to fire the js. Really, if I could just find a way to properly initialize the js with a chron job that would be sufficient.
The key here is that I need it to execute the javascript so I can imitate user actions.
I'm working on a WordPress install, so it would need to be a php or javascript based solution. How can I build something like this?
Use an interaction testing framework like Ember.js. that should allow you to test your UI Interactions.
See the link above to get some detailed information on how to use the library.
Here is a code snippet from the Ember.js library to see if a user is
redirected properly if not authenticated (100% javascript!):
module('Integration: Transitions', {
teardown: function() {
App.reset();
}
});
test('redirect to login if not authenticated', function() {
visit('/');
click('.profile');
andThen(function() {
equal(currentRouteName(), 'login');
equal(currentPath(), 'login');
equal(currentURL(), '/login');
});
});
Ember.js is an excellent way to test your user interactions and your UI components.
Learn more here: http://emberjs.com/guides/testing/testing-user-interaction/
UPDATE:
See this answer for another solution that combines CasperJS and PhantomJS to test user interfaces.
Good luck!
If you don't want to have a browser open to do it you could use a headless browser like PhantomJS

is there a difference between alert() vs notification.alert() using phonegap in xcode?

I'm trying to figure out how to fix the titles on my messages that pop up in my iOS app I am attempting to work on seeing as the messages tend to pop up with a long path of where the file is, then the message which is to a point counter productive for the needs of the popup. That said. I started searching for how to fix it and I came up with the notification.alert(). I am assuming that the standard alert() I am using is binded to that with the way cordova/phonegap works. But does this mean I should instead of alert('message') use notification.alert() if so. Then how can I fix the one that is auto generated by the app when I am looking for geolocation information?
As requested "What am I using for geolocation"
geocoder = new google.maps.Geocoder();
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
Which is what I do in my web based apps. I know this may not be the ideal solution for phonegap/cordova specifically. So I am searching for the right answer to this as well. But mostly the alerts. I am currently porting over an existing web based app to a phonegap version for iOS so the original question is should I remain using alert() where I do in my web based version or should I convert those as well to notification.alert() or does it really make that big a difference.
Like Noogen already mentioned, you should use notification.alert if you want it to look native and you want to customize the title etc.
For iOS 6 and above, to change the alert asking for permission to use current location, you can set the value for key NSLocationUsageDescription (or Privacy - Location Usage Description) in your app's Info.plist. The title of the alert will still be "YourAppBundleName" Would Like to Use Your Current Location. The value of the NSLocationUsageDescription will be shown as an explanation below the title.
There are similar properties for other permission dialogs as described in Apple's Information Property List Key Reference.
What Google geolocation code are you using that is doing the alert? API should not be doing any alert. The alert and notification.alert are two different functions.
Default alert webview/browser display the page URL in the title. Phonegap people did a great thing by providing the additional notification (alert, prompt, and confirm) API. This is a feature/benefit of PhoneGap. It is also required if you don't want to be rejected by Apple with app must be native look and feel clause. Just change all your alert to notification.alert.
You can also hack/override default alert with window.alert = notification.alert, but I do not recommend this.
Alternatively, you can do something like my AngularJS phonegap $notification friendly factory shown in my response here: Angularjs + phonegap logout on history back

Ideas needed. Javascript+XPCOM+C++ add-on

So, there is a WebRTC inside Firefox and there is a convenient class for making RTC communication possible called RTCPeerConnection which can be instantiated and used from the JavaScript app. You can find some decent example of it on [1].
And here am I with my custom transport (if you're interested - [2]) would like to use it for RTC communication. Briefly, I need to "substitute" the transport layer of WebRTC engine by my custom transport while providing the same RTCPeerConnection-like JavaScript interface for the user. And preferably, it should not look like custom build of Firefox (no patches).
So I've come up with the idea of extension, which will be written in C++ (since it need to be linked with WebRTC library and my custom transport library) and somehow will expose its interface to Javascript. And I've found XPCOM which, as I thought, can provide me this.
So I've started to fight with out-dated and sparsed info on this topic and after 3 days of struggling finally ended up with builded add-on. Unfortunately, I can't access it from Javascript, because of Javascript's "Components.classes is undefined" error. And it seems that there is no way to access it at all. Or I'm wrong on that?
Here is Javascript:
function check()
{
console.debug("checking...");
const {Cc,Ci,Cu} = require("chrome");
var rtc = Components.classes["#named-data.net/ndnrtc;1"].createInstance();
rtc = rtc.QueryInterface(Ci.ndINrtc);
console.debug("rtc: "+rtc);
}
My component is visible with XPCOM Viewer addon and the code above I can execute in the console while empty page is open in Firefox.
Given all that, I would like to ask Firefox experts regarding possible approaches which I can take in order to implement my idea.
Thank you in advance
1 https://apprtc.appspot.com/
2 http://named-data.net
Finally, I've figured out one possible solution for that and describe it in my post

Categories