Skip to main content

Synchronous vs. Promise-Based Functions

Some functions return a value immediately, while others return a promise and must be awaited (or chained with .then()). If you use a promise-based function directly, you get back a Promise object instead of the value. Functions that return a value immediately:
  • _aimtellCheckPermissions()
  • _aimtellSupportsPush()
  • _aimtellPrompt()
  • _aimtellForcePrompt()
Functions that return a promise:
  • _aimtellGetSubscriberID()
  • _aimtellGetPushToken()
  • _aimtellGetSubscriberIDFromToken(token)
  • _aimtellGetSubscriberAttributes()
  • _aimtellGetNotifications()
  • _aimtellMarkNotificationsRead(timestamp)
  • _aimtellMarkNotificationsUnread(timestamp)
  • _aimtellDeleteNotifications(timestamp)
Aimtell functions are only available once the script has finished loading. If you’re calling them on page load, do it from inside _aimtellReady().

Check Permissions

Description: Checks visitor’s push notification permissions Params: N/A Response: (str) - granted, default or denied

Example


Supports Push

Description: Checks to see if visitor’s browser supports push notifications Params: N/A Response: (boolean)

Example


Get Subscriber ID

Description: Grabs the active visitor’s subscriber id. If none exists, one is generated. Params: N/A Response: promise, (str) subscriber id

Example

Example response:

Get Push Token

Description: Pulls the device push token from the current visitor. This is delivered as a javascript promise. Params: N/A Response: promise, (str) device token

Example

Example response:
Resolves to null if the visitor isn’t subscribed or the browser doesn’t support push.

Get Subscriber ID From Token

Description: Grabs visitors subscriber id based on push token Params:
  • token - required. browser push token
Response: promise, (obj) result, uid

Example

Example response:
If no subscriber matches the token:

Get Subscriber Attributes

Description: Grabs current website subscriber’s attributes. Params: N/A Response: promise, (obj) with idSite, subscriber_uid and custom_attributes. custom_attributes is an object of your tracked attribute name/value pairs, and is empty if none have been set.
Note: As custom attributes may contain information which an Aimtell website owner may not want easily viewable, this function by default is locked as a security measure. You must specifically request our team to unlock it for your account.

Example

Example response:

Show Push Prompt

Description: If custom push prompt exists, show it, else load native push prompt Params: N/A Response: null

Example


Force Push Prompt

Description: Force shows the custom optin, even if previously denied. Params: N/A Response: null
“Previously denied” refers to the visitor dismissing your custom optin. If the visitor has already granted or denied permission at the browser level, this function does nothing. Browser permissions can only be changed by the visitor in their browser settings.

Example


Get Notifications

Description: Returns the subscriber’s notifications, most recent first. Params: N/A Response: promise, (array) of notification objects with the following fields:
  • title - notification title
  • body - notification body
  • icon - icon URL
  • link - destination URL
  • read - (boolean) true if read, false if unread
  • timestamp - used to target a single notification in the functions below

Example

Example response:
Returns an empty array if the subscriber has no notifications.

Mark Notifications Read

Description: Marks notifications as read. Pass a timestamp to mark a single notification, or call with no arguments to mark all notifications as read. Params:
  • timestamp - optional. The timestamp value from a _aimtellGetNotifications() response item. Pass it through unchanged.
Response: promise, (obj) { updated: <count> }

Example


Mark Notifications Unread

Description: Marks notifications as unread. Pass a timestamp to target one, or omit to mark all notifications as unread. Params:
  • timestamp - optional. The timestamp value from a _aimtellGetNotifications() response item. Pass it through unchanged.
Response: promise, (obj) { updated: <count> }

Example


Delete Notifications

Description: Deletes notifications. Pass a timestamp to delete a single notification, or omit to delete all of the subscriber’s notifications. Params:
  • timestamp - optional. The timestamp value from a _aimtellGetNotifications() response item. Pass it through unchanged.
Response: promise, (obj) { deleted: <count> }

Example