The init()
method initializes Smartlook recorder.
Syntax
init(key)
init(key, options)
init(key, options, doneCallback)
Parameters
key
- Project key.
options
-
Optional object with the initial configuration.
-
region
eu
orus
-
cookies
- (default)
true
- enable storing of metadata in cookies and local storage. false
- disable storing of metadata in cookies, using only local storage.
- (default)
-
relayProxyUrl
string
- Used together with smartlook relay proxy and should be full url with protocol e.g.
https://my-proxy-domain.com/
- Used together with smartlook relay proxy and should be full url with protocol e.g.
-
standalone
-
Boolean
- (default)
false
- makes Smartlook try to establish a connection with the parent window and join the session. The session will be reused only when the parent window loads Smartlook and records it as the same project. See more in the iframe recordings section. if the communication is not established within 10 seconds, the recording starts as a standalone anyway, but these first 10 seconds may be missing. true
- enable when your application is loaded in an iframe and you do not want Smartlook to try to connect with the parent window. Enabling this might be useful especially when you develop a third-party integration (e.g. payment gateway) that is inserted as an iframe on multiple websites.
- (default)
-
-
advancedNetwork
- Object with settings that control network data capture.
- For more information, see Advanced network recording
allowedUrls
- allows recording of request/response bodies
- an
Array
of exact, string patterns or regular expressions
allowedHeaders
- allows recording of non-standard headers
- an
Array
of exact, case-insensitive patterns
-
interceptors
- Object with settings that allows control the data that Smartlook captures.
- For more information, see Interceptors
url
- URL interceptor that can obscure sensitive data from URLs
(data, context) => void
- data—an
object
consisting of- url—
string
URL can be changed
- url—
- context—is not defined
- data—an
network
- Network interceptor that can obscure sensitive data from recorded network calls—bodies, headers, and URLs.
- Network events can be completely omitted by returning
false
from the interceptor. (data, context) => void | false
- data—
object
- url—
string
- request—
object
- headers—
Record<string, Array<string>>
- body—
string
- headers—
- response—
object
- headers—
Record<string, Array<string>>
- body—
string
- headers—
- url—
- context—
object
- pageUrl—
string
URL of the page where the request was initiated.
- pageUrl—
- data—
-
doneCallback
- Optional callback to determine when Smartlook is initialized.
Return value
void
Description
Smartlook.init()
lets you initialize Smartlook. There is one obligatory parameter key
, which you can find in the project settings.
Examples
Simple initialization.
Smartlook.init('YOUR_PROJECT_KEY')
Initialization with region selection.
Smartlook.init('YOUR_PROJECT_KEY', { region: 'eu' })
Initialization with advanced network settings
Smartlook.init('YOUR_PROJECT_KEY', {
region: 'eu',
advancedNetwork: {
allowedUrls: [/.*/],
allowedHeaders: ['x-custom-header'],
}
})
Initialization with interceptors
Smartlook.init('YOUR_PROJECT_KEY', {
region: 'eu',
interceptors: {
url: (data) => {
const tokenIndex = data.url.indexOf('tokenId=');
if (tokenIndex > -1) {
data.url = data.url.slice(0, tokenIndex) + 'tokenId=[OBSCURED]';
}
}
}
})
Initialization with doneCallback
.
Smartlook.init(
'YOUR_PROJECT_KEY',
undefined,
() => console.log('Smartlook is now initialized'),
)