Skip to content

Latest commit

 

History

History
165 lines (112 loc) · 2.78 KB

sdk-api.md

File metadata and controls

165 lines (112 loc) · 2.78 KB

JavaScript SDK API

Since SDK is loaded async way, all it's methods should be called via push([METHOD_NAME, ARGS...]) wrapper. The only exception is when you are 100% sure that it is already loaded and inited. For instance, in events callbacks.

Example:

// Subscribe to notifications
Notimatica.push(['subscribe']);

{.toc}

{#init}

init({Object} options)

Initialize SDK. Should be called on every page of your site.

Note!

This method should be called once. Multiple calls won't cause any additional effect but will show a warning in the browser console.

Params

  • {Object} options - Map of options

Example

Notimatica.push(['init', {
  project: 'PROJECT_ID',
  subdomain: 'SUBDOMAIN'
}]);

{#subscribe}

subscribe()

Start subscription process.

Example

Notimatica.push(['subscribe']);

{#unsubscribe}

unsubscribe()

Unsubscribes user from notifications

Example

Notimatica.push(['unsubscribe']);

{#isSubscribed}

isSubscribed() : {Boolean}

If user is subscribed.

Returns

  • {Boolean} - true if user is subscribed, false if not

Example

if (Notimatica.push(['isSubscribed'])) {
  alert('You are subscribed')
};

{#isUnsubscribed}

isUnsubscribed() : {Boolean}

If user is or was unsubscribed.

Returns

  • {Boolean} - true if user is not subscribed, false if is

Example

if (Notimatica.push(['isSubscribed'])) {
  alert('You are not subscribed')
};

{#on}

on({String} event, {Function} callback)

Subscribe to SDK event.

Params

  • {String} event - Event name
  • {Function} callback - The callback to fire when event is emitted

Example

Notimatica.push(['on', 'ready', function () {
  alert('Notimatica SDK is ready')
}])

{#emit}

emit({String} event)

Trigger the event.

Params

  • {String} event - Event name

Example

Notimatica.push(['emit', 'error', 'Something bad happened'])

{#resetHistory}

resetHistory()

Reset history of received notifications.

Example

Notimatica.push(['resetHistory'])

{#resetState}

resetState()

Reset saved state and settings.

Example

Notimatica.push(['resetState'])

{#resetSDK}

resetSDK()

Reset already inited SDK.

Example

Notimatica.push(['resetSDK'])