Skip to Content
Technical Articles
Author's profile photo Hannes Defloo

Measuring SAP Fiori user statistics with SAP Web Analytics

UPDATE : 22/04/2021: refer to new blog for customers with S/4HANA 2020 or FES 2020.

As part of the SAP S/4HANA Regional Implementation Group, I have the privilege of working with a lot of customers who are implementing SAP S/4HANA locally, regionally, and internationally.

Many of our customers are implementing or are already live with several SAP Fiori apps.  What possibilities do they have to detect how much these are used by the end-users?

One of the possibilities to do this using SAP Web Analytics, this is a service available on the SAP Cloud Platform.  It’s not a free service, you can find details on the pricing here.

Note that there are some other options to do measure user statistics of SAP Fiori :

This blog is not aimed to make a comparison between all the tools but will go further on the option to measure user statistics via SAP Web Analytics. This seems the strategic direction of SAP for web analytics functionality and will be integrated in S/4HANA Cloud and other SAP solutions.  So you can expect more features to become available via this SCP service.

To try it out you can subscribe to a SCP trail account and use SAP Web Analytics with a static website.  This is described step by step in the following document: https://developers.sap.com/mission.cp-web-analytics-get-started.html

After you got this working, the next step would be start measuring the usage data of the SAP Fiori launchpad and apps on your S/4HANA system.

UPDATE 21/04/2021: customers on S/4HANA 2020 or with FES 2020  or higher do not need to create an FLP plugin anymore, it is included in standard in who have SAPUI5 1.78.  See new blog from my colleague Rashmi https://blogs.sap.com/2021/02/18/sap-web-analytics-analytics-solution-for-s4-on-premise-systems/

Customers on S/4HANA 1909 or lower releases create a custom FLP plugin which is started each time users open the SAP Fiori launchpad or apps.  Using SAP WebIDE (or the new Business Application Studio) you can create such a plugin via a template and deploy it on your S/4HANA system.  This was already described in detail with a demo video in the openSAP course “Key Technical Topics in a System Conversion to SAP S/4HANA”, section Week 3, Unit 7: Extensibility Use Cases: SAP Fiori Launchpad.   There is a lot more of interesting content in this openSAP Course, so if you have not yet followed this course, I can really recommend to subscribe to it!  Note again that this custom FLP plugin is not needed anymore with S/4HANA or FES 2020 (and SAPUI5 versions 1.78.x) or higher.

Before you deploy, the FLP plugin will have to be modified to send data to the SAP Web Analytics.  For this you have to replace the Component.js with the following code:

/*!
 * ${copyright}
 */
sap.ui.define([
	"sap/ui/core/Component"
], function(Component) {
	"use strict";

	var SWAComponent = Component.extend("com.sap.rig.wa.Component", {

		metadata: {
			manifest: "json"
		},
        /*global window, sap , document*/
		// Init function called on initialization
		init: function () {
			var oPluginParameters = this.getComponentData().config; // obtain plugin parameters
			var SWA_PUB_TOKEN = "", TRACKING_URL = "", USR = "";
			//Read the variables and pass them
			SWA_PUB_TOKEN = oPluginParameters.SWA_PUB_TOKEN;
			TRACKING_URL = oPluginParameters.SWA_BASE_URL;
			//USR = oPluginParameters.SWA_OWNER;
			USR = sap.ushell.Container.getUser().getEmail();
			this.loadSWAObject(SWA_PUB_TOKEN, TRACKING_URL, true, USR);
			this.loadWebGUI();
		},

		// create SWA object and load track.js
		loadSWAObject: function(SWA_PUB_TOKEN, TRACKING_URL, LOGGING, usr) {
			window.swa = {
				pubToken: SWA_PUB_TOKEN,
				baseUrl: TRACKING_URL,
				loggingEnabled: LOGGING,
				subSiteId: this.setSubSiteId,
				owner: usr
			};

			var d = document, g = d.createElement("script"), s = d.getElementsByTagName("script")[0];
			g.type = "text/javascript";
			g.defer = true;
			g.async = true;
			g.src = window.swa.baseUrl + "js/track.js";
			s.parentNode.insertBefore(g, s);
			if ((typeof sap !== "undefined" && typeof sap.ui !== "undefined") && sap.ui.version < "1.65.0") {
				window.onhashchange = function () {
					window.swa.trackLoad();
				};
			}
		},

		/*Method which listens to web gui announce event and then send the postmessage with baseurl,pubtoken and type as request*/
		loadWebGUI: function () {
			if (window.addEventListener) {
				window.addEventListener("message", function (e) {
					var guiresponse = JSON.parse(e.data);
					if (guiresponse.service === "sap.its.readyToListen" && guiresponse.type === "announce") {
						var swaCookies = escape(window.parent.document.cookie);                         
                   var body = {
                   "type": "request",
                   "service": "sap.its.trackSWA",
                   "pubToken":window.swa.pubToken,
                   "baseUrl":window.swa.baseUrl,
                   "message":"Response from SWA",
                   "isConsentGiven":true,
                   "cookieVal": swaCookies
                   };
						//post the message with pub token and base url
						e.source.postMessage(JSON.stringify(body), e.origin);
					}
				});
			}
		},

		
		
		//Set the subsiteid as each FLP tile where a system acts as a site
		setSubSiteId: function() {
			var subSite = "";

			if (window.location.href.substring(window.location.href.indexOf("#")) !== -1) {
				subSite = window.location.href.substring(window.location.href.indexOf("#") + 1);
			}
			if (subSite.indexOf("&") !== -1) {
				subSite = subSite.substring(0, subSite.indexOf("&"));
			}

			return (subSite !== "") ? subSite : undefined;
		}

	});

	return SWAComponent;

});

Now deploy and activate the FLP plugin to the S/4HANA system as shown in the openSAP video.

You can check if your plugin is successfully deployed, activated and loaded when starting the FLP using your browser developers tools.  Search in the network tab on the technical name of the plugin and you should find it back in the results:

Next step is to configure the plugin to send data to the SAP Web Analytics service. Retrieve the pubToken and baseUrl from your SAP Web Analytics admin cockpit.  Similar as in the tutorial for the static website in the tutorial you have to create a new site for the ABAP FLP.  Then in Site Management, click the Tracking Snippet, here you can find the 2 parameters:

 

In transaction /UI2/FLP_CONF_DEF you have to create an entry for the the FLP Plugin and add the 2 parameters: SWA_BASE_URL and SWA_PUB_TOKEN as string parameters. The UI5 Component ID has to corresponding with the one defined in the FLP plugin (JavaScript).

These 2 values you can configure in the transaction /UI2/FLP_CUS_CONF:

If everything is configured correctly, you should now see entries for your users in the SAP Web Analytics page:

You can also create a custom Dashboard to show FLP specifics like App Usage, List Users, App Usage Time.

In order to show this, you can build a Custom Dashboard with your own reports.  You can see how these are created below.

App Usage:

App Usage Time :

List Users:

 

Hope this blog helps you to try out and setup this up in your S/4HANA on-premise landscape.

 

 Becoming a SAP Fiori for SAP S/4HANA guru

You’ll find much more on our SAP Fiori for SAP S/4HANA wiki

Brought to you by the S/4HANA RIG

 

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Syambabu Allu
      Syambabu Allu

      Hi Hannes,

      Nice feature.Thanks for sharing!

      Thank you,

      Syam

      Author's profile photo Sharath M G
      Sharath M G

      Great blog Hannes.

      I have seen many custom solutions to track usage based on Odata services. Highly inefective, in my view.

      Your solution seems cool.

      Regards,

      Sharath

      Author's profile photo Andrew Varney
      Andrew Varney

      Thanks Hannes.

      I am having 3 issues while trying to implement this.

      1. The SAP Fiori Launchpad Plugin was only available on 1.80 (SAP Innovation) I was warned that this is not compatible with our 1.71.x version
      2. When overwriting the Component.js with your code it is giving ESLINT errors - for example it doesn't like the use of createElement  (sap-no-element creation)
      3. When using transaction /UI2/FLP_CUS_CONF the FLP Properties ID SWA_BASE_URL and SWA_PUB_TOKEN are not available.

      I am on a 1909 system with UI5 1.71

      Regards,

      Jeff

       

      Author's profile photo Hannes Defloo
      Hannes Defloo
      Blog Post Author

      Hi Andrew,

      1. I deployed and is working fine on a 1909 FPS0 system with SAPUI5 1.65, the code should work fine on 1.71 so you can try to ignore this warning.
      2. Can you give some more details on the ESLINT errors, are these with a custom or standard rules ?
      3. You are right, these parameters have to be created first in transaction /ui2/flp_conf_def I will add this to the blog

      Thanks and best regards,

      Hannes

      Author's profile photo Andrew Varney
      Andrew Varney

      Thanks for your response Hannes.

      Regarding the ESLINT errors they will be standard rules as we have not changed them.

      ESLINT%20messages

      The first error (line 38):

      "Direct element creation, create a custom control instead (sap-no-element-creation)"

      Second error(line 45):

      "Global event handling override is not permitted, please modify only single events(sap-no-global-event)"

       

      Perhaps more importantly because it could feed into the above - In WebIDE (I've tested this on 2 different systems) I can pick a New project from template using the most recent UI5 versions on offer:

      I would like to use 1.71, however, the launchpad plugin template is only available in 1.78 (not in any of the others).

      I therefore select 1.78 and when I look at the manifest file that is created by default it has errors around the versions (_version). I then manually fix the version errors by putting in the recommended values that are proposed. It is in this environment that I get the ESLINT errors in the Component file above.

       

      Thanks

      Author's profile photo Ravid Aloni
      Ravid Aloni

      Dear Hannes,

      Is it the only alternative? No other "out-of-the-box" built-in plugin that is easy to configurate and does not with extra costs?

       

      Thank you!
      Ravid

      Author's profile photo Carlo Filiberti
      Carlo Filiberti

      Good morning,

      is this feature only available in SAP Cloud Platform portal with AWS Cloud solutions or it is also possible to have it in an OnPremise HANA installation?

      Best regards

      Author's profile photo Lisa Nemeth
      Lisa Nemeth

      Hi Hannes,

       

      great feature, we'd like to have a look on it in a 1.78.x. System - do you know if the Plug-In is now available in Standard? What's the name?

       

      When we try to use the coding provided by you, the console gives an error message and there's nothing going through to the Service in the cloud (even if we have adjusted our Firewall accordingly).

       

      This is the error message:

      Modules that use an anonymous define() call must be loaded with a require() call; they must not be executed via script tag or nested into other modules. All other usages will fail in future releases or when standard AMD loaders are used or when ui5loader runs in async mode. Now using substitute name ~anonymous~1.js - sap.ui.ModuleSystem

       

      Thank you in advance and best regards,

      Lisa

      Author's profile photo Mantri Shekar
      Mantri Shekar

      HI Annes,

       

      With this SAP Web Analytics can we Capture GUI Apps configured on FLP.Because for me only UI App are capturing but GUI Apps not able to capture

       

       

      Regards,

      Shekar.

      Author's profile photo Amey Suresh Mogare
      Amey Suresh Mogare

      Hello Hannes,

      Thank you for interesting & informative blog.

      I am looking for answers to following two questions. Could you please share your comments?

      1. Is it possible to integrate SAP Web Analytics into standard Fiori applications so that we get insights of what's happening inside them? If yes, could you please point me to some documentation?
      2. Is it possible to read the accumulated data for an application in SAP Web Analytics via some REST API? Objective is to build an intelligent SAPUI5 app that can read this data and adapt the UI so that user gets "personalized" experience in due course of time.

      Warm Regards,

      Amey