├── .assets
├── nuxt_LogRocket.png
└── nuxt_LogRocket.webp
├── .circleci
└── config.yml
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── package.json
├── playground
├── app.vue
├── nuxt.config.ts
└── package.json
├── renovate.json
├── src
├── module.ts
└── runtime
│ └── plugin.client.ts
├── test
└── basic.test.ts
├── tsconfig.json
└── yarn.lock
/.assets/nuxt_LogRocket.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuxt-modules/logrocket/92d0176b6f1d412ba59cf9d70483d7190e898e59/.assets/nuxt_LogRocket.png
--------------------------------------------------------------------------------
/.assets/nuxt_LogRocket.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nuxt-modules/logrocket/92d0176b6f1d412ba59cf9d70483d7190e898e59/.assets/nuxt_LogRocket.webp
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | node:
3 | version: v18.12.1
4 |
5 | version: 2
6 | jobs:
7 | build:
8 | working_directory: ~/project
9 | docker:
10 | - image: node:19.9.0
11 | steps:
12 | # Checkout repository
13 | - checkout
14 |
15 | # Restore cache
16 | - restore_cache:
17 | key: yarn-{{ checksum "yarn.lock" }}
18 |
19 | # Install dependencies
20 | - run:
21 | name: Install Dependencies
22 | command: NODE_ENV=dev yarn
23 |
24 | # Keep cache
25 | - save_cache:
26 | key: yarn-{{ checksum "yarn.lock" }}
27 | paths:
28 | - "node_modules"
29 |
30 | # Test
31 | - run:
32 | name: Tests
33 | command: yarn test
34 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_size = 2
6 | indent_style = space
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@nuxtjs/eslint-config-typescript"
4 | ],
5 | "rules": {
6 | "@typescript-eslint/no-unused-vars": [
7 | "off"
8 | ]
9 | }
10 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | node_modules
3 |
4 | # Logs
5 | *.log*
6 |
7 | # Temp directories
8 | .temp
9 | .tmp
10 | .cache
11 |
12 | # Yarn
13 | **/.yarn/cache
14 | **/.yarn/*state*
15 |
16 | # Generated dirs
17 | dist
18 |
19 | # Nuxt
20 | .nuxt
21 | .output
22 | .vercel_build_output
23 | .build-*
24 | .env
25 | .netlify
26 |
27 | # Env
28 | .env
29 |
30 | # Testing
31 | reports
32 | coverage
33 | *.lcov
34 | .nyc_output
35 |
36 | # VSCode
37 | .vscode
38 |
39 | # Intellij idea
40 | *.iml
41 | .idea
42 |
43 | # OSX
44 | .DS_Store
45 | .AppleDouble
46 | .LSOverride
47 | .AppleDB
48 | .AppleDesktop
49 | Network Trash Folder
50 | Temporary Items
51 | .apdisk
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4 |
5 | ### [2.0.14](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.13...v2.0.14) (2023-07-22)
6 |
7 | ### [2.0.13](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.12...v2.0.13) (2023-07-22)
8 |
9 | ### [2.0.12](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.11...v2.0.12) (2023-07-22)
10 |
11 | ### [2.0.11](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.10...v2.0.11) (2023-07-22)
12 |
13 | ### [2.0.10](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.9...v2.0.10) (2023-07-22)
14 |
15 | ### [2.0.9](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.8...v2.0.9) (2023-07-22)
16 |
17 | ### [2.0.8](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.7...v2.0.8) (2023-07-22)
18 |
19 |
20 | ### Bug Fixes
21 |
22 | * add alias ([dda4994](https://github.com/nuxt-community/nuxt-logrocket/commit/dda499480b7361d94b2c26b4fca605184509c599))
23 |
24 | ### [2.0.7](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.6...v2.0.7) (2023-07-22)
25 |
26 | ### [2.0.6](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.5...v2.0.6) (2023-05-30)
27 |
28 |
29 | ### Bug Fixes
30 |
31 | * test script ([c488712](https://github.com/nuxt-community/nuxt-logrocket/commit/c4887127996f0f167836b9a48306d783ff8c20d9))
32 |
33 | ### [2.0.5](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.4...v2.0.5) (2023-05-30)
34 |
35 |
36 | ### Bug Fixes
37 |
38 | * eslint errors ([ffeeb2a](https://github.com/nuxt-community/nuxt-logrocket/commit/ffeeb2a328725695f8ecae678f2e30655ea5beb6))
39 | * test script ([0d26991](https://github.com/nuxt-community/nuxt-logrocket/commit/0d26991cde44a3e9273e58e3107d9e0fa93c567e))
40 |
41 | ### [2.0.4](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.3...v2.0.4) (2023-01-13)
42 |
43 | ### [2.0.3](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.2...v2.0.3) (2023-01-13)
44 |
45 |
46 | ### Bug Fixes
47 |
48 | * remove .ts from plugin injection ([07595ca](https://github.com/nuxt-community/nuxt-logrocket/commit/07595ca2b42588507c21c74172be432d04767ce8))
49 |
50 | ### [2.0.2](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.1...v2.0.2) (2023-01-13)
51 |
52 | ### [2.0.1](https://github.com/nuxt-community/nuxt-logrocket/compare/v2.0.0...v2.0.1) (2023-01-07)
53 |
54 | ## [2.0.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.5.2...v2.0.0) (2022-12-09)
55 |
56 |
57 | ### ⚠ BREAKING CHANGES
58 |
59 | * `logRocketId` has been renamed to `id`.
60 | * `devModeAllowed` has been renamed to `dev`.
61 | * Environment variables are now handled by the runtime config.
62 |
63 | ### Bug Fixes
64 |
65 | * **circle-ci:** bump node version ([#319](https://github.com/nuxt-community/nuxt-logrocket/issues/319)) ([94c9180](https://github.com/nuxt-community/nuxt-logrocket/commit/94c91800faa9fbc7c5937adcf64310dae4584b8a))
66 |
67 |
68 | * Support Nuxt 3 & Bridge ([39be7be](https://github.com/nuxt-community/nuxt-logrocket/commit/39be7be2dc8f20cc7dd64ab6725d609ff660d5b9))
69 |
70 | ### [1.5.2](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.5.1...v1.5.2) (2020-12-11)
71 |
72 |
73 | ### Bug Fixes
74 |
75 | * handle non existant config ([79b2c6d](https://github.com/nuxt-community/nuxt-logrocket/commit/79b2c6d16f9f8facb0118474cb16b3e7f3e0e69e))
76 |
77 | ### [1.5.1](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.5.0...v1.5.1) (2020-12-11)
78 |
79 | ## [1.5.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.4.0...v1.5.0) (2020-12-09)
80 |
81 |
82 | ### Features
83 |
84 | * add support for LogRocket init() config ([d3699cc](https://github.com/nuxt-community/nuxt-logrocket/commit/d3699ccd6c8cdd182830bebb71687951b49210a8))
85 |
86 | ## [1.4.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.3.0...v1.4.0) (2020-12-09)
87 |
88 |
89 | ### Features
90 |
91 | * integrate with @nuxtjs/sentry module ([8603f41](https://github.com/nuxt-community/nuxt-logrocket/commit/8603f411927477c406a2c21e0c0d8ac34405e8c6))
92 |
93 | ## [1.3.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.11...v1.3.0) (2020-12-08)
94 |
95 |
96 | ### Features
97 |
98 | * add typescript support. ([0265c70](https://github.com/nuxt-community/nuxt-logrocket/commit/0265c704f20cb44fe7865967228eaaee55399d1a))
99 |
100 | ### [1.2.11](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.10...v1.2.11) (2020-06-16)
101 |
102 | ### [1.2.10](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.9...v1.2.10) (2020-05-06)
103 |
104 |
105 | ### Bug Fixes
106 |
107 | * **test:** use nuxt instead of nuxt-edge ([32a19a3](https://github.com/nuxt-community/nuxt-logrocket/commit/32a19a37371a46c8dcc1dda0d2e22b1f4d499e8c))
108 |
109 | ### [1.2.9](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.8...v1.2.9) (2020-05-06)
110 |
111 |
112 | ### Bug Fixes
113 |
114 | * **tests:** remove unused modules section from nuxt.config ([2b40bb0](https://github.com/nuxt-community/nuxt-logrocket/commit/2b40bb06f933f6614ef177bee9953e81d3c4a64e))
115 |
116 | ### [1.2.8](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.7...v1.2.8) (2020-04-09)
117 |
118 |
119 |
120 | ### [1.2.7](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.6...v1.2.7) (2020-02-06)
121 |
122 |
123 |
124 | ### [1.2.6](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.5...v1.2.6) (2020-01-24)
125 |
126 |
127 |
128 | ### [1.2.5](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.4...v1.2.5) (2019-07-17)
129 |
130 |
131 | ### Bug Fixes
132 |
133 | * **plugin:** init LogRocket upon ID existence ([7966b58](https://github.com/nuxt-community/nuxt-logrocket/commit/7966b58))
134 |
135 |
136 |
137 | ### [1.2.4](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.3...v1.2.4) (2019-07-17)
138 |
139 |
140 |
141 | ### [1.2.3](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.2...v1.2.3) (2019-06-26)
142 |
143 |
144 | ### Bug Fixes
145 |
146 | * change working directory ([56d6957](https://github.com/nuxt-community/nuxt-logrocket/commit/56d6957))
147 |
148 |
149 |
150 | ### [1.2.2](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.1...v1.2.2) (2019-05-25)
151 |
152 |
153 |
154 | ## [1.2.1](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.2.0...v1.2.1) (2019-04-27)
155 |
156 |
157 |
158 | # [1.2.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.1.0...v1.2.0) (2019-04-06)
159 |
160 |
161 | ### Features
162 |
163 | * Add environment variables ([161c1bb](https://github.com/nuxt-community/nuxt-logrocket/commit/161c1bb))
164 |
165 |
166 |
167 |
168 | # [1.1.0](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.0.4...v1.1.0) (2019-01-20)
169 |
170 |
171 | ### Features
172 |
173 | * add circleci config ([d3a35bf](https://github.com/nuxt-community/nuxt-logrocket/commit/d3a35bf))
174 |
175 |
176 |
177 |
178 | ## [1.0.4](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.0.3...v1.0.4) (2019-01-20)
179 |
180 |
181 | ### Bug Fixes
182 |
183 | * **readme:** load png logo ([34eecfb](https://github.com/nuxt-community/nuxt-logrocket/commit/34eecfb))
184 |
185 |
186 |
187 |
188 | ## [1.0.3](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.0.2...v1.0.3) (2019-01-19)
189 |
190 |
191 |
192 |
193 | ## [1.0.2](https://github.com/nuxt-community/nuxt-logrocket/compare/v1.0.1...v1.0.2) (2019-01-19)
194 |
195 |
196 |
197 |
198 | ## 1.0.1 (2019-01-19)
199 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Farzad Soltani - Alibaba Travels Co
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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # Nuxt LogRocket
4 |
5 | [](https://npmjs.com/package/nuxt-logrocket)
6 | [](https://npmjs.com/package/nuxt-logrocket)
7 | [](https://circleci.com/gh/nuxt-modules/logrocket)
8 | [](https://codecov.io/gh/nuxt-community/nuxt-logrocket)
9 | [](http://standardjs.com)
10 |
11 | Session replays, product analytics and more for Nuxt apps.
12 |
13 | [📖 **Release Notes**](./CHANGELOG.md)
14 |
15 | ## Features
16 |
17 | - Nuxt 3 & Nuxt Bridge
18 | - Supports [Pinia](https://pinia.vuejs.org) integration
19 | - Ability to run in development mode
20 |
21 | ## Setup
22 |
23 | - Add `nuxt-logrocket` dependency to your project
24 |
25 | ```sh
26 | npm i nuxt-logrocket
27 | ```
28 |
29 | - Add `nuxt-logrocket` to the `modules` section of your `nuxt.config.ts` file
30 |
31 | ```ts
32 | import { defineNuxtConfig } from 'nuxt'
33 |
34 | export default defineNuxtConfig({
35 | modules: ['nuxt-logrocket'],
36 |
37 | logRocket: {
38 | id: '',
39 | dev: false,
40 | config: {
41 | //
42 | }
43 | }
44 | })
45 | ```
46 |
47 | ## Options
48 |
49 | Options can be passed using either [Runtime Config](https://v3.nuxtjs.org/guide/features/runtime-config/#environment-variables) or the `logRocket` section in `nuxt.config.ts`.
50 | Setting a value for the required `id` option is enough in most cases.
51 |
52 | Below is the complete list of options:
53 |
54 | | Option | Type | Default | Required |
55 | | :-- | :-- | :-- | :-- |
56 | | id | `String` | `''` | True |
57 | | dev | `Boolean` | `true` | False |
58 | | enablePinia | `Boolean` | `true` | False |
59 | | release | `String` | `null` | False |
60 | | consoleEnabled | `Boolean` | `true` | False |
61 | | networkEnabled | `Boolean` | `true` | False |
62 | | networkRequestSanitizer | `Function` | - | False |
63 | | networkResponseSanitizer | `Function` | - | False |
64 | | domEnabled | `Boolean` | `true` | False |
65 | | inputSanitizer | `Boolean` | `false` | False |
66 | | textSanitizer | `Boolean` | `false` | False |
67 | | baseHref | `String` | `null` | False |
68 | | shouldCaptureIP | `Boolean` | `true` | False |
69 | | rootHostname | `String` | `null` | False |
70 | | shouldDebugLog | `Boolean` | `true` | False |
71 | | mergeIframes | `Boolean` | `false` | False |
72 |
73 | This is an example containing the default values for the options:
74 |
75 | ```ts
76 | {
77 | id: '',
78 | dev: true,
79 | enablePinia: true,
80 | config: {
81 | release: null,
82 | console: {
83 | isEnabled: true
84 | },
85 | network: {
86 | isEnabled: true,
87 | networkRequestSanitizer: () => {},
88 | networkResponseSanitizer: () => {}
89 | },
90 | dom: {
91 | isEnabled: true,
92 | inputSanitizer: false,
93 | textSanitizer: false,
94 | baseHref: null
95 | },
96 | shouldCaptureIP: true,
97 | rootHostname: null,
98 | shouldDebugLog: true,
99 | mergeIframes: false
100 | }
101 | }
102 | ```
103 |
104 | ## Usage
105 |
106 | LogRocket gets automatically injected into your application when it is setup correctly. By default this module works only in `production` and on client-side events.
107 |
108 | In order to use LogRocket's injected functionality in your application, you can use :
109 |
110 | ```ts
111 | const { $logRocket } = useNuxtApp()
112 | ```
113 |
114 | Visit LogRocket's website for a full list of features : [Docs](https://docs.logrocket.com/docs)
115 |
116 | ### Pinia
117 |
118 | This module automatically detects [Pinia](https://pinia.vuejs.org) store mutations and attaches them to the LogRocket session.
119 |
120 | This functionality is enabled by **default**, and can be disabled by setting the `enablePinia` options to `false`.
121 |
122 | ```ts
123 | import { defineNuxtConfig } from 'nuxt'
124 |
125 | export default defineNuxtConfig({
126 | modules: ['nuxt-logrocket'],
127 |
128 | logRocket: {
129 | id: '',
130 | enablePinia: false
131 | }
132 | })
133 | ```
134 |
135 | ## Development
136 |
137 | - Clone this repository
138 | - Install dependencies using `yarn install`
139 | - Start development server using `yarn run dev`
140 | - Point your browser to `http://localhost:3000`
141 |
142 | ## License
143 |
144 | [MIT License](./LICENSE) - Alibaba Travels Co
145 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-logrocket",
3 | "version": "2.0.14",
4 | "description": "LogRocket module for Nuxt",
5 | "license": "MIT",
6 | "contributors": [
7 | {
8 | "name": "Farzad Soltani "
9 | }
10 | ],
11 | "type": "module",
12 | "exports": {
13 | ".": {
14 | "import": "./dist/module.mjs",
15 | "require": "./dist/module.cjs"
16 | }
17 | },
18 | "main": "./dist/module.cjs",
19 | "types": "./dist/types.d.ts",
20 | "files": [
21 | "dist"
22 | ],
23 | "repository": "https://github.com/nuxt-modules/logrocket",
24 | "publishConfig": {
25 | "access": "public"
26 | },
27 | "scripts": {
28 | "prepack": "nuxt-module-build",
29 | "dev": "nuxi dev playground",
30 | "dev:build": "nuxi build playground",
31 | "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
32 | "test": "yarn dev:prepare && vitest run test",
33 | "lint": "eslint --ext .js,.ts,.vue .",
34 | "lint:fix": "eslint --fix --ext .js,.ts,.vue .",
35 | "release": "yarn lint && yarn test && yarn prepack && yarn standard-version && git push --follow-tags && npm publish"
36 | },
37 | "dependencies": {
38 | "@nuxt/kit": "^3.7.2",
39 | "defu": "^6.1.2",
40 | "logrocket": "^5.0.1"
41 | },
42 | "devDependencies": {
43 | "@nuxt/module-builder": "^0.5.1",
44 | "@nuxt/test-utils": "^3.7.2",
45 | "@nuxtjs/eslint-config-typescript": "latest",
46 | "eslint": "^8.49.0",
47 | "nuxt": "^3.7.2",
48 | "standard-version": "^9.3.2",
49 | "vitest": "^0.34.4"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/playground/app.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Nuxt LogRocket
4 |
5 |
8 |
9 |
12 |
13 |
14 |
15 |
27 |
--------------------------------------------------------------------------------
/playground/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | import { defineNuxtConfig } from 'nuxt/config'
2 | import NuxtLogRocket from '..'
3 |
4 | export default defineNuxtConfig({
5 | modules: [NuxtLogRocket],
6 | logRocket: {
7 | id: ''
8 | },
9 |
10 | typescript: {
11 | shim: false
12 | }
13 | })
14 |
--------------------------------------------------------------------------------
/playground/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nuxt-logrocket-playground",
3 | "private": true
4 | }
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@nuxtjs"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/src/module.ts:
--------------------------------------------------------------------------------
1 | import { defu } from 'defu'
2 | import {
3 | isNuxt3,
4 | addPlugin,
5 | addImports,
6 | useLogger,
7 | createResolver,
8 | defineNuxtModule
9 | } from '@nuxt/kit'
10 | import { name, version } from '../package.json'
11 |
12 | const logger = useLogger('nuxt-logrocket')
13 |
14 | const { resolve } = createResolver(import.meta.url)
15 |
16 | type ModuleOptions = {
17 | /**
18 | * LogRocket ID
19 | * @type {string}
20 | */
21 | id?: string;
22 | /**
23 | * Specify if LogRocket should be enabled in development mode.
24 | * @type {boolean}
25 | * @default true
26 | * */
27 | dev?: boolean;
28 | /**
29 | * Specify if LogRocket should attach pinia mutations to the LogRocket sessions.
30 | * @type {boolean}
31 | * @default true
32 | * */
33 | enablePinia?: boolean;
34 | /**
35 | * LogRocket Configuration
36 | * @type {object}
37 | * */
38 | config?: {
39 | release?: string;
40 | console?: {
41 | isEnabled?:
42 | | boolean
43 | | {
44 | log?: boolean;
45 | info?: boolean;
46 | debug?: boolean;
47 | warn?: boolean;
48 | error?: boolean;
49 | };
50 | shouldAggregateConsoleErrors?: boolean;
51 | };
52 | network?: {
53 | isEnabled?: boolean;
54 | };
55 | dom?: {
56 | isEnabled?: boolean;
57 | baseHref?: string;
58 | textSanitizer?: boolean | string;
59 | inputSanitizer?: boolean | string;
60 | privateAttributeBlocklist?: string[];
61 | };
62 |
63 | /** Controls collection of IP addresses and related features, such as GeoIP */
64 | shouldCaptureIP?: boolean;
65 |
66 | /**
67 | * Enable sharing sessions across subdomains by setting this to the top-level hostname.
68 | * */
69 | rootHostname?: string;
70 |
71 | /**
72 | * Convenience option for configuring the SDK for an on-prem install.
73 | * Include the protocol (eg. https://ingest.example.com)
74 | * */
75 | ingestServer?: string;
76 |
77 | /**
78 | * Convenience option for configuring
79 | * where the full SDK should be loaded from for on-prem installs
80 | * */
81 | sdkServer?: string;
82 |
83 | uploadTimeInterval?: number;
84 |
85 | shouldDebugLog?: boolean;
86 |
87 | mergeIframes?: boolean;
88 |
89 | /**
90 | * Controls domains to which a parent window can post messages
91 | * in order to merge recording with cross-domain iframes
92 | * */
93 | childDomains?: string[] | null;
94 |
95 | /**
96 | * Controls domain to which an iframe window can post messages
97 | * in order to merge recording with a cross-domain parent window
98 | * */
99 | parentDomain?: string | null;
100 |
101 | shouldAugmentNPS?: boolean;
102 |
103 | shouldParseXHRBlob?: boolean;
104 | };
105 | };
106 |
107 | export default defineNuxtModule({
108 | meta: {
109 | name,
110 | version,
111 | configKey: 'logRocket',
112 | compatibility: {
113 | bridge: true
114 | }
115 | },
116 | defaults: nuxt => ({
117 | dev: nuxt.options.dev,
118 | enablePinia: nuxt.options.modules.includes('@pinia/nuxt'),
119 | config: {
120 | console: {
121 | isEnabled: true
122 | },
123 | network: {
124 | isEnabled: true
125 | },
126 | dom: {
127 | isEnabled: true,
128 | inputSanitizer: false,
129 | textSanitizer: false
130 | },
131 | shouldCaptureIP: true,
132 | shouldDebugLog: true,
133 | mergeIframes: false
134 | }
135 | }),
136 | setup (opts, nuxt) {
137 | const options = defu(
138 | isNuxt3()
139 | ? nuxt.options.runtimeConfig.public?.logRocket
140 | // @ts-ignore
141 | : nuxt.options.publicRuntimeConfig.logRocket || {},
142 | opts
143 | )
144 |
145 | nuxt.options.alias.LogRocket = 'LogRocket'
146 |
147 | if (isNuxt3()) {
148 | // @ts-ignore
149 | nuxt.options.runtimeConfig.public.logRocket = options
150 | } else {
151 | // @ts-ignore
152 | nuxt.options.publicRuntimeConfig.logRocket = options
153 | }
154 |
155 | if (!options?.id) {
156 | logger.warn('LogRocket ID not found.')
157 | }
158 |
159 | if (options?.enablePinia) {
160 | logger.info('LogRocket pinia mode enabled.')
161 | }
162 |
163 | addPlugin(resolve('runtime/plugin.client'))
164 |
165 | addImports({
166 | name: 'default',
167 | as: 'LogRocket',
168 | from: 'logrocket'
169 | })
170 | }
171 | })
172 |
173 | declare module '@nuxt/schema' {
174 | interface RuntimeConfig {
175 | // @ts-ignore
176 | public: {
177 | logRocket: ModuleOptions;
178 | };
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/src/runtime/plugin.client.ts:
--------------------------------------------------------------------------------
1 | import LogRocket from '#imports'
2 |
3 | // type inference required to prevent TS4082 error for 'LR.LogRocket'
4 | interface NuxtLR { logRocket: Omit}
5 | export default defineNuxtPlugin(({ pinia }) => {
6 | const opts = useRuntimeConfig()?.public?.logRocket
7 |
8 | if (!opts?.id || (!opts?.dev && !(process.env.NODE_ENV === 'production'))) { return }
9 |
10 | LogRocket.init(opts?.id, opts?.config)
11 |
12 | if (pinia && opts?.enablePinia) {
13 | pinia.use(({ store }) => store.$subscribe(m => LogRocket.log('mutation', m)))
14 | }
15 |
16 | return { provide: { LogRocket } }
17 | })
18 |
--------------------------------------------------------------------------------
/test/basic.test.ts:
--------------------------------------------------------------------------------
1 | import { fileURLToPath } from 'node:url'
2 | import { describe, it, expect } from 'vitest'
3 | import { setup, $fetch } from '@nuxt/test-utils'
4 |
5 | describe('basic', async () => {
6 | await setup({
7 | server: true,
8 | rootDir: fileURLToPath(new URL('../playground', import.meta.url))
9 | })
10 |
11 | it('render', async () => {
12 | const html = await $fetch('/')
13 | expect(html).toContain('Nuxt LogRocket')
14 | }, 60000)
15 | })
16 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./playground/.nuxt/tsconfig.json"
3 | }
--------------------------------------------------------------------------------