├── .prettierignore ├── .gitignore ├── .prettierrc.js ├── tsconfig.cjs.json ├── tsconfig.json ├── yarn.lock ├── LICENSE ├── package.json ├── dist ├── esm │ ├── index.d.ts │ ├── index.js.map │ └── index.mjs └── cjs │ ├── index.js.map │ └── index.cjs ├── README.md └── index.ts /.prettierignore: -------------------------------------------------------------------------------- 1 | index.js 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: false, 3 | useTabs: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | printWidth: 120, 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "target": "es5", 5 | "module": "commonjs", 6 | "allowJs": false, 7 | "declaration": false, 8 | "removeComments": true, 9 | "noImplicitReturns": true, 10 | "noUnusedLocals": true, 11 | "strict": true, 12 | "outDir": "dist/cjs", 13 | }, 14 | "files": ["index.ts"] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "module": "esnext", 5 | "target": "es6", 6 | "allowJs": false, 7 | "declaration": true, 8 | "removeComments": true, 9 | "noImplicitReturns": true, 10 | "noUnusedLocals": true, 11 | "strict": true, 12 | "outDir": "dist/esm" 13 | }, 14 | "files": ["index.ts"] 15 | } -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | typescript@4.6.2: 6 | version "4.6.2" 7 | resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4" 8 | integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg== 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Smartlook 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smartlook-client", 3 | "version": "10.0.0", 4 | "description": "Official Smartlook client for easy frontend integration.", 5 | "main": "./dist/esm/index.mjs", 6 | "types": "./dist/esm/index.d.ts", 7 | "files": [ 8 | "dist/**" 9 | ], 10 | "exports": { 11 | "import": "./dist/esm/index.mjs", 12 | "require": "./dist/cjs/index.cjs", 13 | "types": "./dist/esm/index.d.ts" 14 | }, 15 | "scripts": { 16 | "build:cjs": "tsc -p tsconfig.cjs.json && mv dist/cjs/index.js dist/cjs/index.cjs", 17 | "build:esm": "tsc -p tsconfig.json && mv dist/esm/index.js dist/esm/index.mjs", 18 | "build": "yarn build:esm && yarn build:cjs" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/smartlook/smartlook-client.git" 23 | }, 24 | "keywords": [ 25 | "smartlook", 26 | "smartlook-client" 27 | ], 28 | "author": { 29 | "name": "David Kadlec", 30 | "email": "david@smartlook.com" 31 | }, 32 | "license": "MIT", 33 | "bugs": { 34 | "url": "https://github.com/smartlook/smartlook-client/issues" 35 | }, 36 | "homepage": "https://github.com/smartlook/smartlook-client#readme", 37 | "devDependencies": { 38 | "typescript": "4.6.2" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dist/esm/index.d.ts: -------------------------------------------------------------------------------- 1 | interface Network { 2 | allowedHeaders?: string[]; 3 | allowedUrls?: (string | RegExp)[]; 4 | websockets?: boolean; 5 | } 6 | declare type RequestOrResponse = { 7 | body?: string; 8 | headers?: Record; 9 | }; 10 | interface Interceptors { 11 | click?: (data: { 12 | props?: Record; 13 | text?: string; 14 | url: string; 15 | }, context: MouseEvent) => void | boolean; 16 | error?: (data: { 17 | colno?: number; 18 | filename?: string; 19 | lineno?: number; 20 | message?: string; 21 | stack?: string; 22 | url: string; 23 | }, context: ErrorEvent | PromiseRejectionEvent | Error | string) => void | boolean; 24 | focus?: (data: { 25 | url: string; 26 | }, context: FocusEvent) => void | boolean; 27 | input?: (data: { 28 | url: string; 29 | value: string; 30 | }, context: Event) => void | boolean; 31 | network?: (data: { 32 | request?: RequestOrResponse; 33 | response?: RequestOrResponse; 34 | url: string; 35 | }, context: { 36 | pageUrl: string; 37 | }) => void | false; 38 | url?: (data: { 39 | url: string; 40 | }) => void; 41 | } 42 | export declare type InitParams = { 43 | advancedNetwork?: Network | boolean; 44 | interceptors?: Interceptors; 45 | cookies?: boolean; 46 | region?: 'eu' | 'us'; 47 | relayProxyUrl?: string; 48 | standalone?: boolean; 49 | }; 50 | declare const _default: { 51 | init: (key: string, params?: InitParams | undefined) => boolean; 52 | identify: (userId: string | number, props: { 53 | [key: string]: string | number | boolean; 54 | }) => boolean; 55 | anonymize: () => boolean; 56 | track: (eventName: string, props: { 57 | [key: string]: string | number | boolean; 58 | }) => boolean; 59 | disable: () => boolean; 60 | record: (params: { 61 | forms?: boolean; 62 | ips?: boolean; 63 | numbers?: boolean; 64 | emails?: boolean; 65 | api?: boolean; 66 | }) => boolean; 67 | getData: (callback: () => void) => boolean; 68 | restart: () => boolean; 69 | pause: () => boolean; 70 | resume: () => boolean; 71 | error: (error: string | Error) => boolean; 72 | navigation: (locationOrPath: string) => boolean; 73 | properties: (properties: { 74 | [key: string]: string | number | boolean; 75 | }) => boolean; 76 | initialized: () => boolean; 77 | readonly playUrl: string | undefined; 78 | readonly sessionId: string | undefined; 79 | readonly visitorId: string | undefined; 80 | readonly recordId: string | undefined; 81 | readonly key: string | undefined; 82 | readonly version: string | undefined; 83 | }; 84 | export default _default; 85 | -------------------------------------------------------------------------------- /dist/cjs/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;AACA,IAAM,kBAAkB,GAAG,sCAAsC,CAAA;AA+EjE,kBAAe;IAQd,IAAI,EAAE,UAAU,GAAW,EAAE,MAAmB;QAC/C,IAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,IAAI,CAAC,CAAC,SAAS,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;YACxD,OAAO,KAAK,CAAA;SACZ;QACD,CAAC,CAAC,SAAS,GAAG;YACb,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAChC,CAAC,CAAA;QAED,CAAC,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,CAAA;QAEpB,IAAM,UAAU,GAA+C,MAAM,CAAA;QACrE,IAAI,GAAG,GAAG,2CAA2C,CAAA;QAErD,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,EAAE;YAC9B,IAAI;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C,GAAG,CAAA;IACvB,CAAC;IACD,IAAI,OAAO;QACV,IAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAA;IAC3B,CAAC;CACD,CAAA"} -------------------------------------------------------------------------------- /dist/esm/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AACA,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;AA+EjE,eAAe;IAQd,IAAI,EAAE,UAAU,GAAW,EAAE,MAAmB;QAC/C,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,IAAI,CAAC,CAAC,SAAS,EAAE;YAChB,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;YACxD,OAAO,KAAK,CAAA;SACZ;QACD,CAAC,CAAC,SAAS,GAAG;YACb,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAChC,CAAC,CAAA;QAED,CAAC,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,CAAA;QAEpB,MAAM,UAAU,GAA+C,MAAM,CAAA;QACrE,IAAI,GAAG,GAAG,2CAA2C,CAAA;QAErD,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,EAAE;YAC9B,IAAI;gBACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;gBACxE,UAAU,CAAC,IAAI,GAAG,cAAc,CAAC,MAAM,CAAA;gBACvC,GAAG,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAA;aAC/B;YAAC,OAAO,CAAC,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,iHAAiH,CAAC,CAAA;gBAChI,OAAO,KAAK,CAAA;aACZ;SACD;QAED,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;QAEpC,MAAM,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;YACjB,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAChC,OAAO,KAAK,CAAA;SACZ;QACD,CAAC,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;QACrC,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,WAAW,EAAE;QACZ,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACrB,CAAC;IACD,IAAI,OAAO;QACV,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAA;IAC3B,CAAC;IACD,IAAI,SAAS;QACZ,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,SAAS,CAAA;IAC7B,CAAC;IACD,IAAI,SAAS;QACZ,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,SAAS,CAAA;IAC7B,CAAC;IACD,IAAI,QAAQ;QACX,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAA;IAC5B,CAAC;IACD,IAAI,GAAG;QACN,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,CAAA;IACvB,CAAC;IACD,IAAI,OAAO;QACV,MAAM,CAAC,GAAG,MAAyB,CAAA;QACnC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAA;IAC3B,CAAC;CACD,CAAA"} -------------------------------------------------------------------------------- /dist/esm/index.mjs: -------------------------------------------------------------------------------- 1 | const SL_NOT_INITIALIZED = 'Smartlook client is not initialized.'; 2 | export default { 3 | init: function (key, params) { 4 | const w = window; 5 | if (w.smartlook) { 6 | console.warn('Smartlook client is already initialized.'); 7 | return false; 8 | } 9 | w.smartlook = function () { 10 | w.smartlook.api.push(arguments); 11 | }; 12 | w.smartlook.api = []; 13 | const initParams = params; 14 | let src = 'https://web-sdk.smartlook.com/recorder.js'; 15 | if (initParams === null || initParams === void 0 ? void 0 : initParams.relayProxyUrl) { 16 | try { 17 | const constructedUrl = new URL('/recorder.js', initParams.relayProxyUrl); 18 | initParams.host = constructedUrl.origin; 19 | src = constructedUrl.toString(); 20 | } 21 | catch (e) { 22 | console.error('Smartlook init param `relayProxyUrl` is not valid. Please provide full url like `https://my-proxy-domain.com/`.'); 23 | return false; 24 | } 25 | } 26 | w.smartlook('init', key, initParams); 27 | const head = window.document.getElementsByTagName('head')[0]; 28 | const script = window.document.createElement('script'); 29 | script.async = true; 30 | script.type = 'text/javascript'; 31 | script.crossOrigin = 'anonymous'; 32 | script.src = src; 33 | head.appendChild(script); 34 | return true; 35 | }, 36 | identify: function (userId, props) { 37 | const w = window; 38 | if (!w.smartlook) { 39 | console.warn(SL_NOT_INITIALIZED); 40 | return false; 41 | } 42 | if (!userId) { 43 | console.warn('Smartlook - User ID must be provided'); 44 | return false; 45 | } 46 | w.smartlook('identify', userId, props); 47 | return true; 48 | }, 49 | anonymize: function () { 50 | const w = window; 51 | if (!w.smartlook) { 52 | console.warn(SL_NOT_INITIALIZED); 53 | return false; 54 | } 55 | w.smartlook('anonymize'); 56 | return true; 57 | }, 58 | track: function (eventName, props) { 59 | const w = window; 60 | if (!w.smartlook) { 61 | console.warn(SL_NOT_INITIALIZED); 62 | return false; 63 | } 64 | w.smartlook('track', eventName, props); 65 | return true; 66 | }, 67 | disable: function () { 68 | const w = window; 69 | if (!w.smartlook) { 70 | console.warn(SL_NOT_INITIALIZED); 71 | return false; 72 | } 73 | w.smartlook('disable'); 74 | return true; 75 | }, 76 | record: function (params) { 77 | const w = window; 78 | if (!w.smartlook) { 79 | console.warn(SL_NOT_INITIALIZED); 80 | return false; 81 | } 82 | w.smartlook('record', params); 83 | return true; 84 | }, 85 | getData: function (callback) { 86 | const w = window; 87 | if (!w.smartlook) { 88 | console.warn(SL_NOT_INITIALIZED); 89 | return false; 90 | } 91 | w.smartlook(callback); 92 | return true; 93 | }, 94 | restart: function () { 95 | const w = window; 96 | if (!w.smartlook) { 97 | console.warn(SL_NOT_INITIALIZED); 98 | return false; 99 | } 100 | w.smartlook('restart'); 101 | return true; 102 | }, 103 | pause: function () { 104 | const w = window; 105 | if (!w.smartlook) { 106 | console.warn(SL_NOT_INITIALIZED); 107 | return false; 108 | } 109 | w.smartlook('pause'); 110 | return true; 111 | }, 112 | resume: function () { 113 | const w = window; 114 | if (!w.smartlook) { 115 | console.warn(SL_NOT_INITIALIZED); 116 | return false; 117 | } 118 | w.smartlook('resume'); 119 | return true; 120 | }, 121 | error: function (error) { 122 | const w = window; 123 | if (!w.smartlook) { 124 | console.warn(SL_NOT_INITIALIZED); 125 | return false; 126 | } 127 | w.smartlook('error', error); 128 | return true; 129 | }, 130 | navigation: function (locationOrPath) { 131 | const w = window; 132 | if (!w.smartlook) { 133 | console.warn(SL_NOT_INITIALIZED); 134 | return false; 135 | } 136 | w.smartlook('navigation', locationOrPath); 137 | return true; 138 | }, 139 | properties: function (properties) { 140 | const w = window; 141 | if (!w.smartlook) { 142 | console.warn(SL_NOT_INITIALIZED); 143 | return false; 144 | } 145 | w.smartlook('properties', properties); 146 | return true; 147 | }, 148 | initialized: function () { 149 | const w = window; 150 | return !!w.smartlook; 151 | }, 152 | get playUrl() { 153 | const w = window; 154 | return w.smartlook.playUrl; 155 | }, 156 | get sessionId() { 157 | const w = window; 158 | return w.smartlook.sessionId; 159 | }, 160 | get visitorId() { 161 | const w = window; 162 | return w.smartlook.visitorId; 163 | }, 164 | get recordId() { 165 | const w = window; 166 | return w.smartlook.recordId; 167 | }, 168 | get key() { 169 | const w = window; 170 | return w.smartlook.key; 171 | }, 172 | get version() { 173 | const w = window; 174 | return w.smartlook.version; 175 | }, 176 | }; 177 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/cjs/index.cjs: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var SL_NOT_INITIALIZED = 'Smartlook client is not initialized.'; 4 | exports.default = { 5 | init: function (key, params) { 6 | var w = window; 7 | if (w.smartlook) { 8 | console.warn('Smartlook client is already initialized.'); 9 | return false; 10 | } 11 | w.smartlook = function () { 12 | w.smartlook.api.push(arguments); 13 | }; 14 | w.smartlook.api = []; 15 | var initParams = params; 16 | var src = 'https://web-sdk.smartlook.com/recorder.js'; 17 | if (initParams === null || initParams === void 0 ? void 0 : initParams.relayProxyUrl) { 18 | try { 19 | var constructedUrl = new URL('/recorder.js', initParams.relayProxyUrl); 20 | initParams.host = constructedUrl.origin; 21 | src = constructedUrl.toString(); 22 | } 23 | catch (e) { 24 | console.error('Smartlook init param `relayProxyUrl` is not valid. Please provide full url like `https://my-proxy-domain.com/`.'); 25 | return false; 26 | } 27 | } 28 | w.smartlook('init', key, initParams); 29 | var head = window.document.getElementsByTagName('head')[0]; 30 | var script = window.document.createElement('script'); 31 | script.async = true; 32 | script.type = 'text/javascript'; 33 | script.crossOrigin = 'anonymous'; 34 | script.src = src; 35 | head.appendChild(script); 36 | return true; 37 | }, 38 | identify: function (userId, props) { 39 | var w = window; 40 | if (!w.smartlook) { 41 | console.warn(SL_NOT_INITIALIZED); 42 | return false; 43 | } 44 | if (!userId) { 45 | console.warn('Smartlook - User ID must be provided'); 46 | return false; 47 | } 48 | w.smartlook('identify', userId, props); 49 | return true; 50 | }, 51 | anonymize: function () { 52 | var w = window; 53 | if (!w.smartlook) { 54 | console.warn(SL_NOT_INITIALIZED); 55 | return false; 56 | } 57 | w.smartlook('anonymize'); 58 | return true; 59 | }, 60 | track: function (eventName, props) { 61 | var w = window; 62 | if (!w.smartlook) { 63 | console.warn(SL_NOT_INITIALIZED); 64 | return false; 65 | } 66 | w.smartlook('track', eventName, props); 67 | return true; 68 | }, 69 | disable: function () { 70 | var w = window; 71 | if (!w.smartlook) { 72 | console.warn(SL_NOT_INITIALIZED); 73 | return false; 74 | } 75 | w.smartlook('disable'); 76 | return true; 77 | }, 78 | record: function (params) { 79 | var w = window; 80 | if (!w.smartlook) { 81 | console.warn(SL_NOT_INITIALIZED); 82 | return false; 83 | } 84 | w.smartlook('record', params); 85 | return true; 86 | }, 87 | getData: function (callback) { 88 | var w = window; 89 | if (!w.smartlook) { 90 | console.warn(SL_NOT_INITIALIZED); 91 | return false; 92 | } 93 | w.smartlook(callback); 94 | return true; 95 | }, 96 | restart: function () { 97 | var w = window; 98 | if (!w.smartlook) { 99 | console.warn(SL_NOT_INITIALIZED); 100 | return false; 101 | } 102 | w.smartlook('restart'); 103 | return true; 104 | }, 105 | pause: function () { 106 | var w = window; 107 | if (!w.smartlook) { 108 | console.warn(SL_NOT_INITIALIZED); 109 | return false; 110 | } 111 | w.smartlook('pause'); 112 | return true; 113 | }, 114 | resume: function () { 115 | var w = window; 116 | if (!w.smartlook) { 117 | console.warn(SL_NOT_INITIALIZED); 118 | return false; 119 | } 120 | w.smartlook('resume'); 121 | return true; 122 | }, 123 | error: function (error) { 124 | var w = window; 125 | if (!w.smartlook) { 126 | console.warn(SL_NOT_INITIALIZED); 127 | return false; 128 | } 129 | w.smartlook('error', error); 130 | return true; 131 | }, 132 | navigation: function (locationOrPath) { 133 | var w = window; 134 | if (!w.smartlook) { 135 | console.warn(SL_NOT_INITIALIZED); 136 | return false; 137 | } 138 | w.smartlook('navigation', locationOrPath); 139 | return true; 140 | }, 141 | properties: function (properties) { 142 | var w = window; 143 | if (!w.smartlook) { 144 | console.warn(SL_NOT_INITIALIZED); 145 | return false; 146 | } 147 | w.smartlook('properties', properties); 148 | return true; 149 | }, 150 | initialized: function () { 151 | var w = window; 152 | return !!w.smartlook; 153 | }, 154 | get playUrl() { 155 | var w = window; 156 | return w.smartlook.playUrl; 157 | }, 158 | get sessionId() { 159 | var w = window; 160 | return w.smartlook.sessionId; 161 | }, 162 | get visitorId() { 163 | var w = window; 164 | return w.smartlook.visitorId; 165 | }, 166 | get recordId() { 167 | var w = window; 168 | return w.smartlook.recordId; 169 | }, 170 | get key() { 171 | var w = window; 172 | return w.smartlook.key; 173 | }, 174 | get version() { 175 | var w = window; 176 | return w.smartlook.version; 177 | }, 178 | }; 179 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Smartlook-client 2 | 3 | Imports and initializes Smartlook recorder into a page. 4 | 5 | 1. Installation 6 | ``` 7 | npm install smartlook-client --save 8 | ``` 9 | or 10 | ``` 11 | yarn add smartlook-client 12 | ``` 13 | 2. Import 14 | ``` 15 | import Smartlook from 'smartlook-client' 16 | ``` 17 | or 18 | ``` 19 | const Smartlook = require('smartlook-client') 20 | ``` 21 | 3. API 22 | 23 | ``` 24 | init(key: string) 25 | init(key: string, params) 26 | ``` 27 | Required parameters: 28 | * key: 29 | * Obtained in application at project settings 30 | 31 | Optional parameters: 32 | * advancedNetwork: 33 | * description: 34 | * Object with settings that control network data capture. Advanced network recording allows recording the bodies and headers of requests and responses. 35 | * Read more at https://web.developer.smartlook.com/docs/advanced-network-recording 36 | * `allowedUrls` 37 | * allows recording of request/response bodies 38 | * an Array of exact, string patterns or regular expressions 39 | * `allowedHeaders` 40 | * allows recording of non-standard headers 41 | * an Array of exact, case-insensitive patterns 42 | * `websockets` 43 | * allows recording of websockets 44 | * boolean value 45 | * cookies: 46 | * supported values: 47 | * _(default)_ `true` - enable storing of metadata in cookies and local storage 48 | * `false` - disable storing of metadata in cookies, using only local storage 49 | * example: 50 | * `Smartlook.init('xxxxx', { cookies: false })` 51 | * description 52 | * Use false if you do not want to store recording metadata in cookies 53 | * Note that disabling cookies with block the ability to connect visitors between domain and subdomains. 54 | * Read more at https://help.smartlook.com/en/articles/6064963-cookies-in-smartlook 55 | * interceptors 56 | * description: 57 | * Object with settings that allows control the data that Smartlook captures. 58 | * Read more at https://web.developer.smartlook.com/docs/interceptors 59 | * `url` 60 | * URL interceptor that can obscure sensitive data from URLs 61 | * `network` 62 | * Network interceptor that can obscure sensitive data from recorded network calls—bodies, headers, and URLs. 63 | * Network events can be completely omitted by returning false from the interceptor. 64 | * `error` 65 | * Error interceptor that can obscure sensitive data from error events 66 | * `focus` 67 | * Focus interceptor that can obscure sensitive data from focus events 68 | * `input` 69 | * Input interceptor that can obscure sensitive data from input events 70 | * `click` 71 | * Click interceptor that can obscure sensitive data from click events 72 | 73 | * region: 74 | * supported values: 75 | * `'eu'` 76 | * `'us'` 77 | * example: 78 | * `Smartlook.init('xxxxx', { region: 'us' })` 79 | * description 80 | * Region where data will be captured and stored 81 | * **Do not change** unless told by your sales manager 82 | * relayProxyUrl: 83 | * supported values: 84 | * full URL of self-hosted relay proxy 85 | * e.g. `'https://my-proxy-domain.com/'` 86 | * example 87 | * `Smartlook.init('xxxxx', { relayProxyUrl: 'https://my-proxy-domain.com/' })` 88 | * description: 89 | * Read more at https://help.smartlook.com/en/articles/6120645-smartlook-relay-proxy and https://github.com/smartlook/smartlook-relay-proxy 90 | * standalone: 91 | * supported values: 92 | * _(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. 93 | * `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. 94 | 95 | --- 96 | 97 | ``` 98 | track(string eventName, object props) 99 | ``` 100 | 101 | ``` 102 | identify(integer | string userId, object props) 103 | ``` 104 | 105 | ``` 106 | anonymize() 107 | ``` 108 | 109 | ``` 110 | disable() 111 | ``` 112 | 113 | ``` 114 | record(params: { forms?: boolean, ips?: boolean, emails?: boolean, numbers?: boolean }) 115 | ``` 116 | 117 | ``` 118 | getData(function callback) 119 | ``` 120 | 121 | ``` 122 | restart() 123 | ``` 124 | 125 | ``` 126 | pause() 127 | ``` 128 | 129 | ``` 130 | resume() 131 | ``` 132 | 133 | ``` 134 | error(string | Error error) 135 | ``` 136 | 137 | ``` 138 | navigation(string locationOrPath) 139 | ``` 140 | 141 | ``` 142 | properties(object properties) 143 | ``` 144 | 145 | ``` 146 | initialized() 147 | ``` 148 | 149 | ``` 150 | playUrl 151 | ``` 152 | 153 | ``` 154 | sessionId 155 | ``` 156 | 157 | ``` 158 | visitorId 159 | ``` 160 | 161 | ``` 162 | recordId 163 | ``` 164 | 165 | ``` 166 | key 167 | ``` 168 | 169 | ``` 170 | version 171 | ``` 172 | 173 | 4. Example usage in React 174 | 175 | Usage in other libraries is similar. 176 | 177 | ```js 178 | import React, { Component } from 'react' 179 | import Smartlook from 'smartlook-client' 180 | 181 | class App extends Component { 182 | handleIdentify = () => { 183 | Smartlook.identify(12345, { 184 | name: 'John Doe', 185 | email: 'email@domain.com', 186 | // other custom properties 187 | }) 188 | } 189 | handleTrack = () => { 190 | Smartlook.track('transaction', { 191 | value: 150, 192 | currency: 'usd', 193 | product: 'Product Description', 194 | // other custom properties 195 | }) 196 | } 197 | handlePause = () => { 198 | Smartlook.pause() 199 | } 200 | render() { 201 | return ( 202 |
203 | 204 | 205 | 206 |
207 | ) 208 | } 209 | componentDidMount() { 210 | Smartlook.init('43bc84d9a8406exxxxxxxxxb5601f5bbf8d2ed') 211 | } 212 | } 213 | 214 | export default App 215 | ``` 216 | 217 | For more info visit https://web.developer.smartlook.com/reference/getting-started-with-your-api 218 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | type SmartlookWindow = Window & { smartlook?: any } 2 | const SL_NOT_INITIALIZED = 'Smartlook client is not initialized.' 3 | 4 | interface Network { 5 | allowedHeaders?: string[] 6 | allowedUrls?: (string | RegExp)[] 7 | websockets?: boolean 8 | } 9 | 10 | type RequestOrResponse = { 11 | body?: string 12 | headers?: Record 13 | } 14 | 15 | interface Interceptors { 16 | click?: ( 17 | data: { 18 | props?: Record 19 | text?: string 20 | url: string 21 | }, 22 | context: MouseEvent, 23 | ) => void | boolean, 24 | 25 | error?: ( 26 | data: { 27 | colno?: number 28 | filename?: string 29 | lineno?: number 30 | message?: string 31 | stack?: string 32 | url: string 33 | }, 34 | context: ErrorEvent | PromiseRejectionEvent | Error | string, 35 | ) => void | boolean 36 | 37 | focus?: ( 38 | data: { 39 | url: string 40 | }, 41 | context: FocusEvent, 42 | ) => void | boolean, 43 | 44 | input?: ( 45 | data: { 46 | url: string 47 | value: string 48 | }, 49 | context: Event, 50 | ) => void | boolean 51 | 52 | network?: ( 53 | data: { 54 | request?: RequestOrResponse 55 | response?: RequestOrResponse 56 | url: string 57 | }, 58 | context: { pageUrl: string }, 59 | ) => void | false 60 | url?: (data: { url: string }) => void 61 | } 62 | 63 | export type InitParams = { 64 | // Advanced network recording allows recording the bodies and headers of requests and responses. 65 | advancedNetwork?: Network | boolean 66 | // Interceptors are used to control what data Smartlook captures, and what data sensitive data Smartlook omits. 67 | interceptors?: Interceptors 68 | // metadata in cookies is enabled by default 69 | cookies?: boolean; 70 | // default region is 'eu' 71 | region?: 'eu' | 'us'; 72 | // relayProxyUrl is used together with https://help.smartlook.com/en/articles/6120645-smartlook-relay-proxy and should be full url with protocol e.g. https://my-proxy-domain.com/ 73 | relayProxyUrl?: string; 74 | // (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. 75 | // 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. 76 | // true - enable when your application is loaded in an iframe and you do not want Smartlook to try to connect with the parent window. 77 | // 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. 78 | standalone?: boolean 79 | }; 80 | 81 | export default { 82 | /** 83 | * Initializes the Smartlook web sdk library 84 | * Read more at https://web.developer.smartlook.com/reference/smartlookinit 85 | * 86 | * @param key Project key from project settings 87 | * @param params Optional parameters 88 | */ 89 | init: function (key: string, params?: InitParams): boolean { 90 | const w = window as SmartlookWindow 91 | if (w.smartlook) { 92 | console.warn('Smartlook client is already initialized.') 93 | return false 94 | } 95 | w.smartlook = function () { 96 | w.smartlook.api.push(arguments) 97 | } 98 | 99 | w.smartlook.api = [] 100 | 101 | const initParams: undefined | InitParams & { host?: string } = params 102 | let src = 'https://web-sdk.smartlook.com/recorder.js' 103 | 104 | if (initParams?.relayProxyUrl) { 105 | try { 106 | const constructedUrl = new URL('/recorder.js', initParams.relayProxyUrl) 107 | initParams.host = constructedUrl.origin 108 | src = constructedUrl.toString() 109 | } catch (e) { 110 | console.error('Smartlook init param `relayProxyUrl` is not valid. Please provide full url like `https://my-proxy-domain.com/`.') 111 | return false 112 | } 113 | } 114 | 115 | w.smartlook('init', key, initParams) 116 | 117 | const head = window.document.getElementsByTagName('head')[0] 118 | const script = window.document.createElement('script') 119 | script.async = true 120 | script.type = 'text/javascript' 121 | script.crossOrigin = 'anonymous' 122 | script.src = src 123 | head.appendChild(script) 124 | 125 | return true 126 | }, 127 | identify: function (userId: string | number, props: { [key: string]: string | boolean | number }): boolean { 128 | const w = window as SmartlookWindow 129 | if (!w.smartlook) { 130 | console.warn(SL_NOT_INITIALIZED) 131 | return false 132 | } 133 | if (!userId) { 134 | console.warn('Smartlook - User ID must be provided') 135 | return false 136 | } 137 | w.smartlook('identify', userId, props) 138 | return true 139 | }, 140 | anonymize: function (): boolean { 141 | const w = window as SmartlookWindow 142 | if (!w.smartlook) { 143 | console.warn(SL_NOT_INITIALIZED) 144 | return false 145 | } 146 | w.smartlook('anonymize') 147 | return true 148 | }, 149 | track: function (eventName: string, props: { [key: string]: string | boolean | number }): boolean { 150 | const w = window as SmartlookWindow 151 | if (!w.smartlook) { 152 | console.warn(SL_NOT_INITIALIZED) 153 | return false 154 | } 155 | w.smartlook('track', eventName, props) 156 | return true 157 | }, 158 | disable: function (): boolean { 159 | const w = window as SmartlookWindow 160 | if (!w.smartlook) { 161 | console.warn(SL_NOT_INITIALIZED) 162 | return false 163 | } 164 | w.smartlook('disable') 165 | return true 166 | }, 167 | record: function (params: { 168 | forms?: boolean 169 | ips?: boolean 170 | numbers?: boolean 171 | emails?: boolean 172 | api?: boolean 173 | }): boolean { 174 | const w = window as SmartlookWindow 175 | if (!w.smartlook) { 176 | console.warn(SL_NOT_INITIALIZED) 177 | return false 178 | } 179 | w.smartlook('record', params) 180 | return true 181 | }, 182 | getData: function (callback: () => void): boolean { 183 | const w = window as SmartlookWindow 184 | if (!w.smartlook) { 185 | console.warn(SL_NOT_INITIALIZED) 186 | return false 187 | } 188 | w.smartlook(callback) 189 | return true 190 | }, 191 | restart: function (): boolean { 192 | const w = window as SmartlookWindow 193 | if (!w.smartlook) { 194 | console.warn(SL_NOT_INITIALIZED) 195 | return false 196 | } 197 | w.smartlook('restart') 198 | return true 199 | }, 200 | pause: function (): boolean { 201 | const w = window as SmartlookWindow 202 | if (!w.smartlook) { 203 | console.warn(SL_NOT_INITIALIZED) 204 | return false 205 | } 206 | w.smartlook('pause') 207 | return true 208 | }, 209 | resume: function (): boolean { 210 | const w = window as SmartlookWindow 211 | if (!w.smartlook) { 212 | console.warn(SL_NOT_INITIALIZED) 213 | return false 214 | } 215 | w.smartlook('resume') 216 | return true 217 | }, 218 | error: function (error: string | Error): boolean { 219 | const w = window as SmartlookWindow 220 | if (!w.smartlook) { 221 | console.warn(SL_NOT_INITIALIZED) 222 | return false 223 | } 224 | w.smartlook('error', error) 225 | return true 226 | }, 227 | navigation: function (locationOrPath: string): boolean { 228 | const w = window as SmartlookWindow 229 | if (!w.smartlook) { 230 | console.warn(SL_NOT_INITIALIZED) 231 | return false 232 | } 233 | w.smartlook('navigation', locationOrPath) 234 | return true 235 | }, 236 | properties: function (properties: { [key: string]: string | boolean | number }): boolean { 237 | const w = window as SmartlookWindow 238 | if (!w.smartlook) { 239 | console.warn(SL_NOT_INITIALIZED) 240 | return false 241 | } 242 | w.smartlook('properties', properties) 243 | return true 244 | }, 245 | initialized: function (): boolean { 246 | const w = window as SmartlookWindow 247 | return !!w.smartlook 248 | }, 249 | get playUrl(): string | undefined { 250 | const w = window as SmartlookWindow 251 | return w.smartlook.playUrl 252 | }, 253 | get sessionId(): string | undefined { 254 | const w = window as SmartlookWindow 255 | return w.smartlook.sessionId 256 | }, 257 | get visitorId(): string | undefined { 258 | const w = window as SmartlookWindow 259 | return w.smartlook.visitorId 260 | }, 261 | get recordId(): string | undefined { 262 | const w = window as SmartlookWindow 263 | return w.smartlook.recordId 264 | }, 265 | get key(): string | undefined { 266 | const w = window as SmartlookWindow 267 | return w.smartlook.key 268 | }, 269 | get version(): string | undefined { 270 | const w = window as SmartlookWindow 271 | return w.smartlook.version 272 | }, 273 | } 274 | --------------------------------------------------------------------------------