Store App Visits to an Access Log App

Contents

Overview

This article introduces how to create an Access Log App on Kintone that records users' visits to Kintone Apps. When a user accesses the App, the App ID, the Record ID, the date and time of the access and the user name is recorded in an App.

Sample Image

When users access a record of an App that includes the sample JavaScript customization, it sends data to an Access Log App.

Prepare the App

Create an App (External link) that includes any types of fields. Save the form when finished.

Field type Field name Field code
Number App ID App_ID
Number Record ID Record_ID
Created by User User
Created datetime Datetime Datetime

Sample Code

Type the following code into a text editor and save it as a JavaScript file. Replace the value of the app parameter to the App ID of the App where the access log will be stored. Navigate to an App that will track the users' access to the records. Upload the sample JavaScript file to App's JavaScript and CSS Customization settings (External link) .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function() {
  'use strict';
  kintone.events.on('app.record.detail.show', function(event) {
    // Get the App ID
    var appId = event.appId;
    // Get the Record ID
    var recordId = event.recordId;
    // Request parameters as JSON
    var params = {
      'app': 108, // Enter the App ID of App where the logs will be stored
      'record': {
        'App_ID': {'value': appId},
        'Record_ID': {'value': recordId}
      }
    };

    // Use the Kintone REST API request to run kintone's Add Record API
    kintone.api(
      kintone.api.url('/k/v1/record.json', true), // - pathOrUrl
      'POST', // - method
      params, // - params
      function(resp) { // - callback
        // (do nothing)
      },
      function(resp) { // - errback
        // (do nothing)
      }
    );
  });
})();

After saving the settings, update the App. Navigate to any record of the App. The App ID, Record ID, Date and the User data should be added in as a record inside the Access Log App.

Reference