Constructor
new Now4real()
You cannot use this constructor directly. An instance of this class is already available globally under window.now4real.
Members
(readonly) ErrorCode :ErrorCode
Enum encompassing all potential error codes in Now4real.
(readonly) Subject :Subject
Enum representing subscribable subjects in Now4real.
(readonly) config :Now4real~Config
Configuration object that contains the configured values.
onerror :Now4real~onerrorCallback
Callback function called when the library has failed to load.
Example
window.now4real = {};
now4real.onerror = function (error) {
console.log('Now4real failed to load', error.code, error.message)
}
onload :function
The callback function called when the library is fully loaded, and it is possible to start calling API methods.
Note that the library implements a lazy loading mechanism so that it waits for the visible state of the host page (see Page Visibility API) in order to load.
Example
window.now4real = {};
now4real.onload = function () {
console.log('Now4real loaded!')
}
(readonly) pageContext :string
A constant string containing the Page Context of the current page. It's configurable through the page_context
property of the config object, otherwise it is automatically computed by the library.
The Page Context (combined with the Site Context) allows Now4real to decide whether different users should be considered present on the same page. The term "page" means an actual web page or some logical context (group of pages, virtual place, etc.). This directly impacts page counters, pagechats, rankings, maps, etc.
The default Page Context corresponds to the window.location.pathname, with the following exceptions:
- If the pathname terminates with /index.*, /Index.*, /home.*, /Home.*, /default.* or /Default.*, the Page Context will be truncated to the last "/".
- If the page was loaded from the "file://" protocol, the Page Context will be "/" followed by the name of the file (including any extension).
Examples:
Url | Page Context |
---|---|
https://example.com/path/page.html | /path/page.html |
https://example.com/path/page.html#hash | /path/page.html |
https://example.com/page5?par=val | /page5 |
https://example.com/page5/ | /page5/ |
http://example.com/path/index.html | /path/ |
file:///Users/integrator/Desktop/project/app.html | /app.html |
http://localhost/project/app.html | /project/app.html |
Examples of URLs that point all to the same Page Context:
Url | Page Context |
---|---|
https://example.com/technology/ | /technology/ |
https://example.com/technology/index.html | /technology/ |
https://example.com/technology/index.htm | /technology/ |
https://example.com/technology/Home.aspx | /technology/ |
https://example.com/technology/?id=3 | /technology/ |
https://example.com/technology/index.html?id=4 | /technology/ |
If the
page_context
property of the config object is used, the behavior of the examples above might be very different. For example, you may include some query parameters, or you may completely remap the actual page path to a different name. Please refer to the documentation of the page_context
property for a few examples.
(readonly) siteContext :string
A constant string containing the Site Context of the current page. It is automatically computed by the library and represents the website to which this page pertains. Generally, it corresponds to the window.location.host of the page.
If a hierarchy of domain name aliases and subdomains has been configured in the Now4real Publisher Dashboard, the value may be different from window.location.host: for the top-level site, the configured "master" domain is returned; for a subdomain, the first subdomain name in the subdomain group is returned.
Notice that the protocol ("http://" or "https://") is not considered for the Site Context. The TCP port is considered only if it's not 80 or 443.
The Site Context allows Now4real to decide whether different users are on the same site. This directly impacts site counters, rankings, maps, etc.
As a special case, a sandbox context is available, which allows you to test your Now4real code without mounting it on an actual domain.
This context, named "shared-public-sandbox.test" automatically originates in these cases:
- If the page is loaded with the "file://" protocol (from the file system).
- If the hostname is "localhost".
- If the IP address is a loopback address (like 127.0.0.1).
Examples:
Url | Site Context |
---|---|
http://example.com/path/page.html | example.com |
https://example.com/path/page2?par=val | example.com |
https://www.example.com/path/page3#abc | example.com (if example.com was configured in the Dashboard as the master for example.com and www.example.com domains) |
https://example.com:8443/path/page.html | example.com:8443 |
http://localhost:8080/project/app.html | shared-public-sandbox.test |
http://127.0.0.1:8080/project/dev | shared-public-sandbox.test |
file:///Users/integrator/Desktop/project/page.html | shared-public-sandbox.test |
(readonly) version :string
A constant string representing the version of the library.
Example
// returns "1.0.0"
now4real.version
Methods
closePoll(removeopt) → {Promise}
Method that allows closing the currently open poll in the current Page context.
Once closed, the results will be frozen, and users will no longer be able to vote, although they will still be able to view the results. Optionally, by passing the "remove" parameter as true, you can completely remove the current poll.
The method can only be called by users with the moderator or guest role and only if there is an open poll in the current Page context.
If successful, the "POLL_STATUS" and "POLL" subjects will receive an update with the "closed" field of the poll object set to true. If removed, they will receive null instead. At this point, it is possible to open a new poll again using the createPoll method.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidCallError, NotAuthenticatedError, NotFoundError, ServiceUnavailableError, or TechnicalProblemError.
[Not in Free Plan]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
remove |
boolean |
<optional> |
A boolean value indicating whether to completely remove the poll. Default is false. |
Example
// close the current poll
await now4real.closePoll()
// completely remove the current poll
await now4real.closePoll(true)
createPoll(question, answers, optionsopt) → {Promise}
Method that allows opening a poll in the current Page context.
Polls enable users to express their preference related to the posed question; they are entirely anonymous and optionally allow multiple-choice answers.
The method can only be called by users with the moderator or guest role, and only if there isn't already another poll open in the same Page context.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
If successful, this call will trigger an update for the "POLL_STATUS" and "POLL" subjects, providing information about the newly opened poll.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, AlreadyPresentError, ChatDisabledError, DisconnectedError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
[Not in Free Plan]
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
question |
string |
The question of the poll. Must be maximum 100 characters. |
|||||||||
answers |
Array.<string> |
An array containing the possible answers for the poll. Each answer must be maximum 25 characters. Must contain between 2 and 10 answers. |
|||||||||
options |
object |
<optional> |
An optional object containing additional options. Properties
|
Example
await now4real.createPoll('What is your favorite music genre?', ['Rock', 'Pop', 'Metal'], { multipleChoice: false })
deleteMessage(msgId) → {Promise}
Method that deletes the message with the passed msgId from the current pagechat.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
Each user can only request the deletion of their own messages. Moderators can delete any messages.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidArgumentsError, NotAuthenticatedError, NotAuthorizedError or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
msgId |
string |
The id of the message to delete. |
Example
now4real.deleteMessage('MSG_ID_000000042')
.then(_ => {
console.log('deleteMessage succedeed')
})
.catch(reason => {
console.log('deleteMessage error', reason.code, reason.message)
})
editUserProfile() → {Promise}
Method that opens a new browser tab in which the user has the possibility to edit some attributes of their profile, created previously with email signup.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user, by means of email, must be present.
After a successful update of the user profile, all the subjects that contain a reference to that user will receive an update.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, BlockedError, InvalidCallError, or TechnicalProblemError.
Example
now4real.editUserProfile()
.then(_ => {
console.log('edit popup opened')
})
.catch(reason => {
console.log('error on opening edit popup', reason.code, reason.message)
})
flushChat() → {Promise}
Method that entirely flush the current pagechat. It can be called only by a logged in Moderator.
If the call is successful, the "LIST_CHAT_MESSAGES" subject will receive a series of "REMOVE" updates which lead to empty the chat.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
Example
now4real.flushChat()
.then(_ => {
console.log('flushChat succeeded')
})
.catch(reason => {
console.log('flushChat error', reason.code, reason.message)
})
get(subject) → {*}
Method that returns the current value of a subscribed subject.
It can be the latest update data object for a counter or a poll-related subject, or the latest snapshot object for the other subjects, such as a ranking or a heatmap. See: CounterUpdate, PollStatusUpdate, PollUpdate, Heatmap, MessageList, Ranking, and TypingList.
The same value can be retrieved as a property access on the Now4real instance.
Parameters:
Name | Type | Description |
---|---|---|
subject |
Subject | string |
The name of the subject (which must be already subscribed to). |
Throws:
Will throw an instance of Now4realError, specifically one of the following: InvalidArgumentsError if the argument is not a valid subject or InvalidCallError if the subject is valid but is not currently subscribed.
Examples
// returns {value: "1"}
now4real.get(now4real.Subject.COUNTER_PAGE_VIEWERS)
// returns [{ isCurrentPage: true, key: 'example.com/hello.html', title: "example page", url: "http://example.com/hello.html", users: "5" }]
now4real.get(now4real.Subject.RANKING_PAGE_VIEWERS)
// returns {value: "1"}
now4real[now4real.Subject.COUNTER_PAGE_VIEWERS]
getMute(userId) → {Promise}
Method that gets the configured mute period for the user, if any.
It returns a promise that resolves with a mutePayload or null, depending on the presence of the mute for the user, or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidArgumentsError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
userId |
string |
The id of the user. |
Example
now4real.getMute('USER_ID_0000000099')
.then(response => {
console.log('getMute succeeded', response.expiration)
})
.catch(reason => {
console.log('getMute error', reason.code, reason.message)
})
getPollVote() → {Promise}
Method that allows obtaining the vote of the currently authenticated user in the current poll.
The method can only be called if there is a poll, even if closed, in the current Page context.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
It returns a promise that resolves with a getPollVotePayload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidCallError, NotAuthenticatedError, NotFoundError, ServiceUnavailableError, or TechnicalProblemError.
[Not in Free Plan]
Example
// retrieve the vote submitted by the user, indicating their choice for the first option
const { vote } = await now4real.getPollVote()
console.log(vote) // output: [0]
login(provideropt) → {Promise}
Method that initiates the authentication flow in a new browser tab.
Login is required in order to be able to post messages to the chat.
The specific flow the user will follow depends on how the current site has been configured in the Now4real Dashboard (see the "Authentication" tab in site settings). Please consider that this method doesn't work when "JWT authentication" is selected.
In case of "Social and email login" configuration, the user navigates to a page in which they chooses the authentication provider. This step is perfomed only if the provider parameter is not defined.
If a social provider is chosen, the user proceeds with authentication on the selected social network (if not already signed in) and is prompted to authorize Now4real to access some information on their profile. If the email provider is choosen, the user is taken to a profile creation page in our system (if it doesn't exist), where they can select their preferred email and a custom nickname. The flow is passwordless and involves entering a 6-digit code sent to the chosen email.
In case of "No registration" configuration, the user can simply enter a nickname to join the chat without any registration.
Upon successful authentication, the login information is stored in a localStorage object within our domain. For the "Social and email login" configuration, this information is available to other sites with the same authentication configuration that integrate Now4real and are opened in the same browser. Furthermore, all the browser tabs which have a compatible authentication (including the one that has started the flow) will be notified through a call of the "LOGIN_STATUS" subject callback.
The method returns a promise that resolves with a loginPayload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, AlreadyStartedError, BlockedError, InvalidArgumentsError, InvalidCallError, ServiceUnavailableError, or TechnicalProblemError.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
provider |
string |
<optional> |
The login provider to use for authentication. It can be |
Example
now4real.login('GOOGLE')
.then(response => {
console.log('login succedeed', response.user)
})
.catch(reason => {
console.log('login error', reason.code, reason.message)
})
logout() → {Promise}
Method that performs a logout of the currently signed in Now4real user from the current browser.
If the call is successful, all the browser tabs (including the one that has requested the logout) will be notified through a call of the "LOGIN_STATUS" subject callback.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, InvalidCallError, ServiceUnavailableError, or TechnicalProblemError.
Example
now4real.logout()
.then(_ => {
console.log('logout succeeded')
})
.catch(reason => {
console.log('logout error', reason.code, reason.message)
})
post(msg, optionsopt) → {Promise}
Method that posts the passed message to the current pagechat on behalf of the currently logged in Now4real user.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
The maximum allowed message length can be retrieved from the "PARAMETERS" subject, while the minimum interval between two consecutive messages is provided in the response of a successful invocation.
It returns a promise that resolves with a postPayload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, ChatbotError, ChatDisabledError, DisconnectedError, InvalidArgumentsError, NotAuthenticatedError, NotAuthorizedError, ServiceUnavailableError, TechnicalProblemError, TooFrequentError, or UserMutedError.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msg |
string |
The message that will be posted to the current pagechat. |
|
options |
Now4real~PostOptions |
<optional> |
The options for the current operation. |
Examples
now4real.post('Hello there!')
.then(_ => {
console.log('post succedeed')
})
.catch(reason => {
console.log('post error', reason.code, reason.message)
})
now4real.post('Thanks for the code!!!', { replyTo: 'MSG_ID_000000037' })
.then(_ => {
console.log('post succedeed')
})
.catch(reason => {
console.log('post error', reason.code, reason.message)
})
registerUserConsent() → {Promise}
Method that notifies the Now4real cloud that the current logged-in JWT user has accepted Now4real's Terms of Service and Privacy Policy.
This method must be called, in case of custom authentication, before a user sends their first message. Otherwise, any call to the post method would throw an error.
A check of the consentGiven
attribute of the current user allows you to understand if the user has already provided their consent and therefore there is no need to call this method again.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in JWT user must be present.
If successful, this call will trigger an update for the 'POLL_STATUS' and 'POLL' subjects, providing information about the newly opened poll.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
Example
const currentUser = now4real.LOGIN_STATUS.user
if (!currentUser.consentGiven) {
// here the user has to explicitly accept Now4real's Terms of Service and Privacy Policy
// the consent must be stored on the Now4real cloud
await now4real.registerUserConsent()
}
await now4real.post('Hi!')
reload()
Method that requests Now4real reinitialization. Once the reloading process is complete, a call to the onload callback will be re-issued.
It is advisable to call the method only when there are no other calls awaiting resolution. If this happen, the calls would be aborted and their outcome would not be guaranteed.
It can be used to update the launch configuration without the need for a page refresh.
Developers that want to support their SPA sites, offering a different pagechat for each route, can call this method when navigation occurs, to update the Now4real widget context. In this case, the widget must be loaded with a page scope. Remember that, if the SPA is based on hashed URL paths, the page_context
parameter needs to be configured and updated accordingly.
Examples
// update widget configuration
now4real.config.widget.color_external_background = '#123456'
now4real.reload()
// detect navigation
watch:{
$route (to, from) {
now4real.reload()
}
}
// detect navigation
watch:{
$route (to, from) {
now4real.config.page_context = '/chat/' + location.hash
now4real.reload()
}
}
reportMessage(msgId, reason, commentopt) → {Promise}
Method that allows a user to report a message published by other users on the current pagechat, if he finds any issues with it.
Reports containing these messages will be sent to the email addresses configured in the "User Reporting" section of the Dashboard (according to the configured frequency), who can then decide whether to remove these from the pagechat.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, AlreadyReportedError, DisconnectedError, InvalidArgumentsError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, TechnicalProblemError, or UserMutedError.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
msgId |
string |
The id of the message to report. |
|||||||||||||||||
reason |
string |
The reason of the report. Must be one of the following:
|
|||||||||||||||||
comment |
string |
<optional> |
Additional information the user want to include in the report. The supplied string can contain up to 500 characters. |
sendVote(vote) → {Promise}
Method that allows users to submit a vote in the current poll. This can contain a single preference or more, depending on whether the poll is single-choice or multiple-choice.
The method can only be called if there is an open poll in the current Page context.
Upon calling, the "POLL" subject will receive an update containing the updated poll results.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real user must be present.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, ClosedError, ChatDisabledError, DisconnectedError, InvalidCallError, NotAuthenticatedError, NotFoundError, ServiceUnavailableError, or TechnicalProblemError.
[Not in Free Plan]
Parameters:
Name | Type | Description |
---|---|---|
vote |
Array.<number> |
An array of numbers indicating the 0-based index of the poll answers that the user wants to vote for. |
Example
// the user votes for the first answer in the current single-choice poll
await now4real.sendVote([0])
// the user votes all the answers in the current multiple-choice poll
await now4real.sendVote([0, 1, 2])
setChatEnabled(enabled) → {Promise}
Method that allows to disable or re-enable the current pagechat. It can be called only by a logged in Moderator.
If the call is successful, the "PARAMETERS" subject will be notified with the updated chatStatus value.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidArgumentsError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
enabled |
boolean |
false to disable to chat, true to re-enable it. |
Example
now4real.setChatEnabled(false)
.then(_ => {
console.log('setChatEnabled succeeded')
})
.catch(reason => {
console.log('setChatEnabled error', reason.code, reason.message)
})
setLoggerLevel(level) → {Promise}
Method that changes the logging level of the library.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, or InvalidArgumentsError.
Parameters:
Name | Type | Description |
---|---|---|
level |
string |
The new logging level of the library. |
setMute(userId, duration) → {Promise}
Method that allows to mute a user in the pagechat for a period of time. The user cannot post any messages until the mute expiration.
In order for the call to be successful, the client must be connected to the Now4real cloud, and a logged-in Now4real Moderator must be present.
It can be called multiple times on the same user, even before the expiration. The mute period will be recomputed and updated at each call.
It returns a promise that resolves with a mutePayload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, DisconnectedError, InvalidArgumentsError, InvalidCallError, NotAuthenticatedError, ServiceUnavailableError, or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
userId |
string |
The id of the user to mute. |
duration |
number |
The period of time, in seconds, in which the user will be muted and can't post messages. It is possible to pass null to mute the user forever. |
Example
now4real.setMute('USER_ID_0000000099', 60)
.then(response => {
console.log('setMute succeeded, the user is muted until: ' + new Date(response.expiration).toUTCString())
})
.catch(reason => {
console.log('setMute error', reason.code, reason.message)
})
startTyping() → {Promise}
Method that notifies the Now4real cloud that the current Now4real user has started typing a message for the current pagechat.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, InvalidCallError, NotAuthorizedError, or TechnicalProblemError.
stopTyping() → {Promise}
Method that notifies the Now4real cloud that the current Now4real user has stopped typing a message for the current pagechat.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, InvalidCallError or TechnicalProblemError.
subscribe(subject, callback) → {Promise}
Method that sets a listener for subject updates.
The passed callback function is called each time an update pertaining to the subject has been received from the Now4real cloud with the corresponding instance of Now4realSubjectUpdate.
For some subjects ["COUNTER_PAGE_VIEWERS", "COUNTER_PAGE_CHATTERS", and "COUNTER_CHAT_TYPING"] it is possible to choose a custom Page Context by appending a colon followed by the Page Context just after the subject name. [Not in Free Plan]
Due to performance optimizations, after some time the page is no more visibile (typically because it is gone in the background), the subscribed subjects may no longer receive updates. The normal behavior will be restored when the page becomes visible again.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, InvalidArgumentsError, InvalidCallError, NotAuthorizedError, or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
subject |
Subject | string |
The name of the subject to subscribe to. Must be one of the values defined in the Subject enum. |
callback |
Now4real~subjectUpdateCallback |
Callback function that is called each time an update pertaining to the subscribed subject has been received from the Now4real cloud. |
Examples
await now4real.subscribe(now4real.Subject.COUNTER_PAGE_VIEWERS, updObj => {
console.log('counter update received: ' + updObj.data.value)
})
await now4real.subscribe(`${now4real.Subject.COUNTER_PAGE_VIEWERS}:my-great-path/test.html`, updObj => {
console.log('counter update received: ' + updObj.data.value)
})
unsubscribe(subject) → {Promise}
Method that removes a registered listener from a subject.
It returns a promise that resolves with an empty object payload or rejects with an instance of Now4realError, specifically one of the following: AbortedError, InvalidArgumentsError, InvalidCallError, or TechnicalProblemError.
Parameters:
Name | Type | Description |
---|---|---|
subject |
Subject | string |
The name of the subject to unsubscribe from. |
Type Definitions
Config :object
Configuration object to be provided to the API, which contains the configuration settings.
Properties:
Name | Type | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
target |
string | "widget" |
Defines what should be loaded.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
scope |
string | "site" |
Defines whether to create a single pagechat for the whole site or a different pagechat for every page of the site.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger |
string | "warn" |
Defines the initial logging level of the library.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
context_check |
string | boolean | false |
Should be the window.location.host of the page in which Now4real will be loaded. It is used to check whether the site was cloned and to automatically block Now4real loading. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
param_overriding |
boolean | false |
Enables or disables the option to override the
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
page_context |
string | object | null |
Defines a custom Page Context for the current page. This gives you full control over how Now4real should treat each page of your site, allowing you to consider even query strings and fragments, or to override the page path completely.
Properties
Examples: Current URL: https://example.com/shop/shoes?type=sneakers&sort=price_ascending#comments
WARNING: Ensure you strip any sensitive attributes, like usernames, passwords, tokens, unique ids, etc. Page contexts may easily get public (for example, in page rankings). NOTE: Please consider that the resulting pageContext is also used to create the links in the PAGES section of the widget (that is, the url property of RankingUpdate). If you are displaying the PAGES section, ensure the resulting URLs are valid because users may click those links.
Defining a custom page_context may be useful even when the scope is set to "site", in case you want to alter the URLs displayed in the PAGES section of the widget. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
custom_auth |
object |
Defines custom authentication settings. [Not in Free Plan] Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
widget |
object |
Defines widget configuration settings. Properties
|
Examples
<script type="text/javascript">
window.now4real = {};
now4real.config = {
target: 'api+widget',
widget: {
align: 'right',
align_mobile: 'left',
color_external_background: '#da3f3f',
color_external_text: '#ece15d'
}
};
(function () { var n4r = document.createElement('script'); n4r.type = 'text/javascript'; n4r.async = true; n4r.src = 'https://cdn.now4real.com/now4real.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(n4r, s); })();
</script>
<script type="text/javascript">
// With the now4real.config below, the widget, the API, and the log will be disabled
// for everyone (even if presence is still silently collected). But setting
// param_overriding to true allows you to override such behavior for a given browser.
// To enable the widget on the fly, just call any page of the site once with this
// query string:
// https://example.com/?n4rTarget=widget
// Similarly, to set the log to debug, use this query string:
// https://example.com/?n4rLogger=debug
// You can use both the parameters together:
// https://example.com/?n4rTarget=widget&n4rLogger=debug
// That browser will remember the new settings for any future visits to any pages of
// that site. To switch back to the original settings, just call any page of the site
// once with this query string:
// https://example.com/?n4rTarget=default&n4rLogger=default
window.now4real = {};
now4real.config = {
target: 'none',
logger: 'off',
param_overriding: true
};
(function () { var n4r = document.createElement('script'); n4r.type = 'text/javascript'; n4r.async = true; n4r.src = 'https://cdn.now4real.com/now4real.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(n4r, s); })();
</script>
Heatmap :Object.<string, number>
A dictionary object that represents a Heatmap. It has string keys representing the country
and number values representing the intensity
.
MessageList :array
An array that represents the messages available in the current pagechat.
Properties:
Name | Type | Description |
---|---|---|
id |
string |
The unique identifier of the message. |
message |
string |
The message body. |
author |
User |
The user who sent the message. |
timestamp |
number |
The number of milliseconds from the Unix Epoch to the time the message was sent. |
isMine |
boolean |
Indicates whether the message was sent by the current Now4real user. |
PostOptions :object
An object that contains the options for the post call.
Properties:
Name | Type | Description |
---|---|---|
replyTo |
string |
The id of the message to reply to. |
Ranking :array
An array that represents a ranking.
Properties:
Name | Type | Description |
---|---|---|
key |
string |
The context that uniquely identifies the page. |
url |
string |
The full url of the page. |
title |
string |
The page title, if available, otherwise the Page Context. |
users |
string |
The counter value, following the same rules of the CounterUpdate value. |
isCurrentPage |
boolean |
Indicates whether the page is the same as the one in which the library is working. |
TypingList :Array.<User>
An array that represents the typing list.
getPollVotePayload :object
Properties:
Name | Type | Description |
---|---|---|
vote |
Array.<number> |
An array of numbers indicating the indices of the poll options that the user has voted for. |
loginPayload :object
Properties:
Name | Type | Description |
---|---|---|
user |
CurrentUser |
The authenticated user. |
persistent |
boolean |
false if the custom authentication is being used or, in case of social login, if there are restricted privacy settings on the user browser, which prevent the library from saving the authentication object into the local storage. In that case, the login will not be remembered across page navigations. true otherwise. |
mutePayload :object
Properties:
Name | Type | Description |
---|---|---|
expiration |
number |
The number of milliseconds from the Unix Epoch to the time the user can post messages again into the pagechat or null if the user was muted forever. |
onerrorCallback(error) → {void}
Parameters:
Name | Type | Description |
---|---|---|
error |
Now4realError |
The error encountered while loading. |
postPayload :object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
waitPeriod |
number |
The number of milliseconds to wait before sending another message on behalf of the logged-in user in the current pagechat. Sending a new message before this delay expires will result in an error. |
|
suggestions |
Array.<string> |
<optional> |
An optional list of suggestions returned by the configured chatbot webhook. These suggestions are available only if a chatbot is configured in the current pagechat and can be used to guide the next steps in the conversation with the chatbot. |
subjectUpdateCallback(subjectUpdate) → {void}
Parameters:
Name | Type | Description |
---|---|---|
subjectUpdate |
Now4realSubjectUpdate |
The object that contains the update data. |