SDK For Data Streaming
JavaScript
8min
include the javascript resource file with the following cdn reference link in the body tag and preferably in a global location such as your index html or the global javascript file please include one of the following script reference and replace the placeholders with your api credentials \<script src="https //sdk qualetics com/qualetics js sdk v3 js">\</script> include only one of the above script references once the event tracking api is initialized, automatic page level events are captured and streamed automatically without any additional code in the application that will be streaming the data, initialize the qualetics api object using the following initialization script replace the placeholders application id, application secret and client id with the api credentials provided to you or generated from the qualetics portal see creating your account docid\ s3f7bpkxxlafhs fehvdd \<script> var qualetics = new qualetics service("application id", "application secret", "application prefix", pageview tracking, options); qualetics init() \</script> additional options the following options can be set while initiating the connection { host string, port number, defaultactor actor object, stickysessionid boolean, storedefaultactorfromapicall boolean, trackusergeolocation boolean, trackpagevisibilitychanges boolean, appversion string, disableerrorcapturing boolean, captureclicks boolean, capturetimings boolean } host string host that tracker will connect to defaults to wss\ //api qualetics com port number port that tracker will connect to defaults to 443 defaultactor actor object default actor for all the messages this can be the actor information once logged in and will retain for all further automatic page view tracking custom events will still require an actor object stickysessionid boolean store sessionid as cookie, if a stored sessionid has a different session prefix than what is configured, a new session id will be generated and it will be stored defaults to true, only usable on browser storedefaultactorfromapicall boolean store default actor from api call this setting will have no effect if default actor setting is set defaults to true, only usable on browser trackusergeolocation boolean include users geolocation information as metadata this will prompt an alert to the user and requires their approval to track locations defaults to false, only usable on browsers trackpagevisibilitychanges boolean track users page exits and returns automatically defaults to true appversion string version number or the code of the application using the sdk no default value disableerrorcapturing boolean automatically captures all js and http errors when using the js sdk defaults to false captureclicks boolean when true, all click events are automatically captured defaults to false capturetimings boolean when true, the page load times are automatically captured defaults to false example initialization script \<script> var qualetics = new qualetics service("qualetics", "supersecretpassword", "app qualetics com", true, {host "wss\ //api qualetics com", port 443, appversion "1 0 1", trackusergeolocation true, captureclicks true, capturetimings true}); qualetics init() \</script> custom event creation in addition to automatic tracking, qualetics api allows you to track custom events from your application enabling you to gather data for specific events examples of such events are a user performing a login action in your application adding a product to the cart completing a purchase adding a product review performing a search for a specific item such events can contain valuable data that can aid to understanding your application and also help with additional data collection following is an example of how such events can be captured using the entities of actor, action, context and object var eventobj = { "actor" { "type" "user", "id" "js1234", "attributes" {"name" "john doe"} }, "action" { "name" "buy product", "attributes" {"referrer" "facebook", "coupon" "kihsk123fs"} }, "context" { "type" "product promotion", "name" "superbowl sales", "attributes" {"discount" "half off"} }, "object" {"type" "television", "name" "samsung", "attributes" {"model" "xyz123", "item price" "$1299", "screen" "60 inches"} }}; sending events the event can be sent either by sending the complete json object qualetics send(eventobj); or using the builder message builder let message = qualetics createmessage(); message setaction({ type "buttonclick" }) setactor({ type "user", id "js1234", attributes {name "john doe"} }) setaction({ name "buy product", attributes {"referrer" "facebook", "coupon" "kihsk123fs"} }) setcontext({ type "product promotion", name "superbowl sales", attributes {"discount" "half off"} }) setobject({ type "television", name "samsung", attributes {"model" "xyz123", "item price" "$1299", "screen" "60 inches"} }) send(); all automatic and custom events will be processed and available as insights in the portal created