How to Record Custom User Actions

To make customizations such as those described below, you use a directory in your SmartHub installation at the root level.

A Customization folder (<SmartHub_install_root>\CustomerCustomization\) and files are provided by default, which can be used as templates (make a copy of the CustomerCustomization directory and modify the files within to suit your needs.

For more information, see How to Customize Your SmartHub User Interface.

How to Add a New Analytics Module

  1. Open your SmartHub installation directory.

  2. Navigate to your customization folder and add a new file <your module name>-module.js(this is where your custom action logic is going to be).
    1. For example,page-like-module.jswould register every click on the Like button from the SmartHub page

  3. Navigate to the SmartHub root directory.

  4. Open the file DefaultModuleSettings.js file under /modules/SmartHubResourceLoader.
    1. Copy the contents of the settingPAXModulesunder the sectionSH.Analytics.DefaultSettings.

  5. Go back to your customization folder and open the page's custom settings file (such as the Results.html page custom settings file ResultsCopyCustomSettings.js)
    1. Add the path to the new file into the sectionSH.Loader.FilesToLoad.


    2. Locate the sectionSH.Analytics.CustomSettingsand paste the previously copied contents
    3. Inside the PAXModulesarray, add PAX_<your module name>Module

How to Edit the Custom Module

  1. Inside the new <your module name>-module.js file, paste the code below.

  2. Change the window.PAX_PageLikeModule to match the name from step 5.c., above, as well as the PageLike action name inside the injectionMap structure. 

  3. customBinding triggers the registering of the action 
    1. In the sample code, a click event is attached to the element with the "like-button" ID.

  4. ThepageLikeCallback function structure remains the same, but the name must be changed

  5. contextMap maps the action to the callback function called when the event is triggered
    1. For instance, getPageLikeContextis a function that adds the Timestampto the context when the button is clicked

  6. artifactSchemas must be changed to match the fields you registered inside the callback function
    1. For the page "Like" action, theTimestampfield should be added besides the user-related ones

page-like-module.js
Copy
(function () {
 
    var _contexts = {};
    var _callback;
 
    var getPageLikeContext = function () {
        var context = {};
 
        context['Timestamp'] = new Date();
 
        return context;
    };
 
    var pageLikeCallback = function (args) {
        _callback(args, _contexts["PageLike"]);
    };
 
    window.PAX_PageLikeModule = {
 
        injectionMap: {
            PageLike: {
                customBinding: function (context, callback) {
                    if (_contexts["PageLike"]) return;
 
                    _contexts["PageLike"] = context;
                    _callback = callback;
                     
                    pax.$('#like-button').on('click', function (e, data) {
                        pageLikeCallback();
                    });
 
                }
            }
        },
 
        contextMap: {
            PageLike: getPageLikeContext
        },
 
        contextKeysMap: {
            // union of states for each artifact referenced.
            PageLike: ['pageLike']
        },
 
        states: ['PageLike'],
 
        goalStates: [],
 
        additionalVisitPropertiesCallbacks: [],
 
        additionalSessionPropertiesCallbacks: [],
 
        actionTypes: {
            // action are interpreted differently with respect to phase and time.
            // a long hover is good (duration).  a long wait for a page load (latency) is bad.
            // some actions are atomic (download), and some are phased (pageload request, page load response),
            // some actions are indeterminate (pulsed)
            // logging sees everything as events. we need some hints to translate event sequences into actions for metric.
 
            PageLike: { type: 'atomic' }
        },
 
        artifactSchemas: {
            // what's the schema for what we persist? is specific to stuff from the app. state provided by context callbacks.
 
            pageLike: ['Timestamp', 'PageURL', 'User', 'AccountName', 'Department', 'Office', 'JobTitle', 'Title', 'UserLocation', 'Birthday', 'TimeZone', 'Manager', 'PastProjects', 'Skills', 'HireDate', 'YearsWithCompany']
        }
    };
})();