inhabit-module-base
A base module for building an InHabit Module.
TOC
Installation
npm install --save-dev inhabit-module-base
Usage
var InhabitModuleBase = ; { InhabitModuleBase; ...} MyModuleprototype = Object;MyModuleprototypeconstructor = MyModule;... InhabitModuleBase;
You have access to next features of Inhabit through base class:
Semantic service
This service allows you to grab contextual information about your page for later use.
dependenciestextClassificationService; //information about url that was classified can be achieved from this property dependenciestextClassificationServicecurrentUrl
Taxonomy
getTaxonomy method returns promise that results into the array of taxonomy information about this page.
dependenciestextClassificationService
where "taxonomy" is array:
"values": "sports" "football" "score": 0990101 "values": "business and industrial" "logistics" "freight train" "score":036197 ...
vales in this case are dependent from each other, you should read them like this sports->football; business and industrial->logistics->freight train For full list of available taxonomy please look this document Taxonomy reference
Entities
getEntities - method returns promise that results into array of entities relevant to this page.
dependenciestextClassificationService
where "entities" is array:
"values": "Matt Jones" "score": 082653 "type": "Person" "values": "Coach Jay Gruden" "score": 0668899 "type": "Person" "misc": "subType": "FootballPlayer" "SportsOfficial" "name": "Jay Gruden"
List of available types and sub types
Keywords
getKeywords - method returns promise that results into array of keywords, keywords are broader view of text than entities and taxonomy based on words that could be used to describe meaning of the text
dependenciestextClassificationService
where "keywords" is array:
"values": "Monday night" "score": 0926018 "values": "Coach Jay Gruden" "score": 0746022
V2
getTextClassification - method returns promise that results into array of requested classification.
thistextClassificationService;
AB tests
dependenciesabTestManager;
AB test manager allows you to extend your object properties and add AB test support for them For example you have property:
var myTitle = configurationtitle;
that you receive from json configuration delivered by Inhabit platform
{ "modules": [ { "id": "myModule", "title":"My Title" } ] }
If you want to AB test this property, simply change you json to this
"modules": "id": "myModule" "title": // id of abTest should be gloabally unique, it is good to // name it according to what you test and add date when you added test "abTest":"testTitle-01/21/2017" // experiment explanation, contains array of arrays with desired values and probability of their appearence for the use. // at this case 50% time you will see "Click me" and another 50% "My Title" "experiment": "Click me!"05 "My title"05 // if referesh property set to true, user will see new result each time he refresh the page. I false, // user will always see value that he seen at first time. For example if he seen "Click me!" title he will // see this title all the time during the test. "refresh":true
And then at your code:
var myTitle = dependenciesabTestManager;
That's it now AB test will automatically set proper value based on you weights If you will reveret your configration to the previous one without AB test in it, there no need to change code, it will still work properly. So next time you will need to run abTest, you will need just change configuration.
You can use ABTest manager for any javascript object if you want;
Logger
dependencieslogger;
Logger - built-in logger can be enabled in production through specific configuration, allows you debug your application in production. Logger logs to browser console and enabled by default in dev environment, while disabled in production. Using this logger allow you to keep all your logging code and be silent in production environment
Usage:
dependencies; dependencies; dependencies;
don't forget to enable DevMode as well
<script async="" ... data-ark-log="true" src="//widgetapi-inhabit.as.arkadiumhosted.com/Widget/v1"></script>
Events
dependenciesevents
Ready
Call this method when interactive loaded all required resources and ready to be displayed to the user
dependenciesevents
message[optional] - if you need any message attached to the ready event, this message can be later used in analytics dashboard for example
Error
Call this method if any error appears in your application. This will help to track them down and make your application better
dependenciesevents
message[optional] - if you need any message attached to the error event, this message can be later used in analytics dashboard for example
InteractionStart
Call this method when user performs first interaction with application. This event should be called once per application lifetime
dependenciesevents
message[optional] - if you need any message attached to the interactionStart event, this message can be later used in analytics dashboard for example
CycleStart
Call this method when user starts iteration/cycle/sequence of logic in your application
dependenciesevents
message[optional] - if you need any message attached to the cycleStart event, this message can be later used in analytics dashboard for example
CycleEnd
Call this method when user end iteration/cycle/sequence of logic in your application
dependenciesevents
message[optional] - if you need any message attached to the cycleEnd event, this message can be later used in analytics dashboard for example
Custom
You can use this event to propagate any custom messages for analytics purposes
dependenciesevents
name - name of the event message[optional] - if you need any message attached to the custom event, this message can be later used in analytics dashboard for example
Run method this.events.refreshAd() on user click if you want to refresh ad block inside the InHabit, it will fire event:
thisevents
ModalPopup
dependenciesmodalPopup
Open popup window with your custom url, use method:
dependenciesmodalPopup
Open terms of service popup window, use method:
dependenciesmodalPopup
Resources root
Provides absolute url to your resources root. Use this to reference all images and other resources you will use in your code
dependenciesresourcesRoot;