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
- Open your SmartHub installation directory.
- 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).
- For example,page-like-module.jswould register every click on the Like button from the SmartHub page
- For example,page-like-module.jswould register every click on the Like button from the SmartHub page
- Navigate to the SmartHub root directory.
- Open the file DefaultModuleSettings.js file under /modules/SmartHubResourceLoader.
- Copy the contents of the settingPAXModulesunder the sectionSH.Analytics.DefaultSettings.
- Copy the contents of the settingPAXModulesunder the sectionSH.Analytics.DefaultSettings.
- 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)
- Add the path to the new file into the sectionSH.Loader.FilesToLoad.
- Locate the sectionSH.Analytics.CustomSettingsand paste the previously copied contents
- Inside the PAXModulesarray, add PAX_<your module name>Module
- Add the path to the new file into the sectionSH.Loader.FilesToLoad.
How to Edit the Custom Module
-
Inside the new <your module name>-module.js file, paste the code below.
- 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.
- customBinding triggers the registering of the action
- In the sample code, a click event is attached to the element with the "like-button" ID.
- In the sample code, a click event is attached to the element with the "like-button" ID.
- ThepageLikeCallback function structure remains the same, but the name must be changed
- contextMap maps the action to the callback function called when the event is triggered
- For instance, getPageLikeContextis a function that adds the Timestampto the context when the button is clicked
- For instance, getPageLikeContextis a function that adds the Timestampto the context when the button is clicked
- artifactSchemas must be changed to match the fields you registered inside the callback function
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']
}
};
})();