Show TOC

Initializing the Usage LibraryLocate this document in the navigation structure

Initialize the usage library to configure the database on-device, and the upload manager to send records to the server.

Context

The usage library initialization call will do the following:
  1. Build the database on-device if it is not already configured.
  2. Set the HttpConversationManager session used to upload records to the server.
  3. Attempt to POST any existing records in the database server.

Procedure

Initialize the usage library.

The sap.Usage.init() call takes only the fully-qualified endpoint where the records are uploaded, an optional database encryption key, and an integer value representing the number of days the Usage plugin waits to have Wi-Fi connectivity before submitting records over cellular data. The Logon plugin onRegistrationSuccess callback is a good location for invoking the sap.Usage.init() call. For example:

sap.Logon.init(onRegistrationSuccess, function() {}, appId, context, sap.Logon.IabUi);
	    
	var onRegistrationSuccess = function(result) {
	
		var host = result.registrationContext.serverHost;
		var path = '/clientusage';
		var uploadUrl = "https" + '://' + host + ":443" + path;
		var timeFor3GUpload = 3;
	
		sap.Usage.init(
			uploadEndpoint,
			encryptionKey,
			timeFor3GUpload,
			function() { /* onSuccess callback */ },
			function() { /* onError callback */ }
		);
	}