1.0.3 • Published 3 years ago

usergeek-js v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Usergeek-JS

You can install the Usergeek JavaScript SDK as an NPM package or as an HTML code snippet

Installation

HTML snippet

Paste the HTML script tag snippet within the <head> tag of your page and initialize with your project token. Usergeek Javascript SDK will be loaded asynchronously.

<script>
!function(e,t){const r=e.Usergeek||{},n=t.createElement("script");n.type="text/javascript",n.crossOrigin="anonymous",n.async=!0,n.src="https://cdn.usergeek.com/libs/usergeek-1.0.3.min.gz.js",n.onload=function(){e.Usergeek.success||console.log("[Usergeek] Error: could not load SDK")};const o=t.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o),function(){function e(e,t,r){e[t]=function(){r.push([t].concat(Array.prototype.slice.call(arguments,0)))}}r.q=[];const t="createInitConfiguration initializeWithApiKey".split(" ");for(const n in t)e(r,t[n],r.q);function n(t,n,o){o=o.split(" "),r[t]=[],r[n]=function(){const n={};for(const s in o)e(n,o[s],r[t]);return n}}n("qc","getClient","setUserId resetUserId setUserProperty setOnceUserProperty unsetUserProperty incrementUserProperty appendUserProperty removeUserProperty logEvent flush"),n("qdpc","createDevicePropertyConfig","trackProperty trackCacheProperty")}(),e.Usergeek=r}(window,document);
</script>

Once the initial code snippet has run, the Usergeek object is available globally and ready to use.

NPM

You can install the npm module and embed the Usergeek Javascript SDK into your code

npm install -D usergeek-js

Import the Usergeek Javascript SDK in your code

import {Usergeek} from "usergeek-js"
//or
const {Usergeek} = require("usergeek-js")

Usage

Initialization

You will need your project token to initialise the Usergeek Javascript SDK. You can find your project token at www.usergeek.com.

Simple initialization

Usergeek.initializeWithApiKey("<API_KEY>")

Initialization with options

const devicePropertyConfig = Usergeek.createDevicePropertyConfig()
devicePropertyConfig.trackCacheProperty("appVersion", () => "1.2.3")

const initConfiguration = Usergeek.createInitConfiguration()
initConfiguration.devicePropertyConfig = devicePropertyConfig
initConfiguration.enableSessionTracking = true

Usergeek.initializeWithApiKey("<API_KEY>", initConfiguration)

Setting User Id

The User Id can be set either upon initializing the Usergeek Javascript SDK, or after initialization with the setUserId method.

const initConfiguration = Usergeek.createInitConfiguration()
initConfiguration.initialUserId = "9aaaaaaa-5555-6666-7777-0d57dc9ec874" 
Usergeek.initializeWithApiKey("<API_KEY>", initConfiguration)
Usergeek.getClient().setUserId("9aaaaaaa-5555-6666-7777-0d57dc9ec874")

Sending Events

//event
Usergeek.getClient().logEvent("StartConversation")
//event with properties (to add additional context about the event)
Usergeek.getClient().logEvent("EndConversation", {
    conversationType: "public",
    conversationSettings: "default"
})

User Properties

User properties help you understand your users at the time they performed some action within your app

Setting a User Property

set

setUserProperty sets the value of a user property.

Usergeek.getClient().setUserProperty("locale", "en")
setOnce

setOnceUserProperty sets the value of a user property only once. Subsequent calls on a particular user property will be ignored.

Usergeek.getClient().setOnceUserProperty("locale", "en")
unset

unsetUserProperty unsets the value of a user property.

Usergeek.getClient().unsetUserProperty("locale")
increment

incrementUserProperty increments a user property by some numerical value.

Usergeek.getClient().incrementUserProperty("friendsInvited", 2)
append

appendUserProperty appends a value to a user property array.

Usergeek.getClient().appendUserProperty("favoriteMovieGenres", "comedy")
remove

removeUserProperty removes a value from a user property array.

Usergeek.getClient().removeUserProperty("favoriteMovieGenres", "drama")

License

Usergeek-JS is distributed under the terms and conditions of the MIT license.

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago