Get Device ID in Oracle APEX

How to Get Device ID in Oracle APEX?

  • Create a page with a page item and paste below Javascript in Function and Global Variable Declaration section as per screenshots.
function getCookie(name) {
		    var cookieValue = null;
		  if (document.cookie && document.cookie !== '') {
		      var cookies = document.cookie.split(';');
		       for (var i = 0; i < cookies.length; i++) {
		           var cookie = cookies[i].trim();
		            // Does this cookie string begin with the name we want?
		          if (cookie.substring(0, name.length + 1) === (name + '=')) {
		              cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
		              break;
		           }
		      }
		 }
		    return cookieValue;
	}
		function uuidv4() {
		  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
		    return v.toString(16);
		  });
		}
		let device = getCookie('device')

		if (device == null || device == undefined){
			device = uuidv4()
		}

		document.cookie ='device=' + device + ";domain=;path=/"
        apex.item( "PX_DEVICE_ID" ).setValue( device);
     //apex.item( "P26_DEVICE_ID" ).getValue(device) ;

Demo

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *