Skip to Content
Technical Articles

Measuring SAP Fiori user statistics with SAP Web Analytics

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/tutorials/cp-webanalytics-create-sample-website.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.

This is done via a 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 that this custom FLP plugin will probably not be needed anymore in upcoming SAPUI5 versions 1.78.x, it is planned to be included by default.

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. The UI5 Component ID has to corresponding with the one defined in the FLP plugin (JavaScript).

These 2 values you can now 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

 

5 Comments
You must be Logged on to comment or reply to a post.
  • 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

  • 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

     

    • 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

      • 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