Skip to content

Commit f42eee3

Browse files
committed
refact: Update ReadMe, add env vars and change module namespace
1 parent ae8de7c commit f42eee3

13 files changed

+3236
-3162
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

-38
This file was deleted.

.github/ISSUE_TEMPLATE/testing.md

-1
This file was deleted.

CHANGELOG.md

-6
This file was deleted.

LICENSE

-21
This file was deleted.

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) Dans Ma Culotte <contact@dansmaculotte.fr>
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
13+
> all 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
21+
> THE SOFTWARE.

README.md

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,77 @@
1-
# nuxt-segment-analytics
1+
# nuxt-segment
22

33
[![David-DM][david-dm-src]][david-dm-href]
44
[![Standard JS][standard-js-src]][standard-js-href]
5-
[![Circle CI][circle-ci-src]][circle-ci-href]
6-
[![Codecov][codecov-src]][codecov-href]
75
[![npm version][npm-version-src]][npm-version-href]
86
[![npm downloads][npm-downloads-src]][npm-downloads-href]
97

10-
> NuxtJS module for Stripe.js
11-
12-
[📖 **Release Notes**](./CHANGELOG.md)
8+
> NuxtJS module for Segment Analytics
139
1410
This module uses [vue-segment-analytics](https://github.com/Kapiche/vue-segment-analytics) to add Segment Analytics to a Nuxt.js app.
15-
You can make called with this.$analytics.track()
11+
You can make called with `this.$segment.track()`.
1612

1713
## Setup
1814

19-
- Add `nuxt-segment-analytics` dependency using yarn or npm to your project
20-
- Add `nuxt-segment-analytics` to `modules` section of `nuxt.config.js`
15+
- Add `nuxt-segment` dependency using yarn or npm to your project
16+
- Add `nuxt-segment` to `modules` section of `nuxt.config.js`
2117

2218
## Usage
2319
### nuxt.config.js
2420
```js
2521
{
2622
modules: [
27-
// Simple usage
28-
'nuxt-segment-analytics',
23+
'nuxt-segment'
24+
],
2925

30-
// With options
31-
['nuxt-segment-analytics', { id: "SEGMENT_KEY", useRouter: true }],
32-
]
26+
segment: {
27+
sourceId: '',
28+
useRouter: true
29+
}
3330
}
3431
```
3532

33+
## Options
34+
35+
### sourceId
36+
37+
- Type: `String`
38+
- Default: `process.env.SEGMENT_SOURCE_ID || ''`
39+
40+
### useRouter
41+
42+
- Type: `Boolean`
43+
- Default: `process.env.SEGMENT_USE_ROUTER || true`
44+
3645
### YourComponent.vue
3746
```js
3847
export default {
3948
mounted () {
40-
this.$analytics.identify('f4ca124298', {
49+
this.$segment.identify('f4ca124298', {
4150
name: 'Michael Bolton',
4251
email: 'mbolton@initech.com'
43-
})
44-
this.$analytics.track('Signed Up', { plan: 'Enterprise' })
45-
this.$analytics.page('Pricing');
52+
});
53+
this.$segment.track('Signed Up', { plan: 'Enterprise' });
54+
this.$segment.page('Pricing');
4655
}
4756
}
4857
```
4958

50-
5159
## Development
5260

5361
- Clone this repository
54-
- Install dependencies using `yarn install` or `npm install`
62+
- Install dependencies using `yarn install`
5563
- Start development server using `npm run dev`
5664

5765
## License
5866

59-
[MIT License](./LICENSE)
60-
61-
Copyright (c) Dylan Wight <dylan@otechie.com>
67+
[MIT License](./LICENSE.md)
6268

6369
<!-- Badges -->
64-
[david-dm-src]: https://david-dm.org/https://github.com/dgwight/nuxt-segment-analytics/status.svg?style=flat-square
65-
[david-dm-href]: https://david-dm.org/https://github.com/dgwight/nuxt-segment-analytics
70+
[david-dm-src]: https://david-dm.org/dansmaculotte/nuxt-segment/status.svg?style=flat-square
71+
[david-dm-href]: https://david-dm.org/dansmaculotte/nuxt-segment
6672
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
6773
[standard-js-href]: https://standardjs.com
68-
[circle-ci-src]: https://img.shields.io/circleci/project/github/https://github.com/dgwight/nuxt-segment-analytics.svg?style=flat-square
69-
[circle-ci-href]: https://circleci.com/gh/https://github.com/dgwight/nuxt-segment-analytics
70-
[codecov-src]: https://img.shields.io/codecov/c/github/https://github.com/dgwight/nuxt-segment-analytics.svg?style=flat-square
71-
[codecov-href]: https://codecov.io/gh/https://github.com/dgwight/nuxt-segment-analytics
72-
[npm-version-src]: https://img.shields.io/npm/dt/nuxt-segment-analytics.svg?style=flat-square
73-
[npm-version-href]: https://npmjs.com/package/nuxt-segment-analytics
74-
[npm-downloads-src]: https://img.shields.io/npm/v/nuxt-segment-analytics/latest.svg?style=flat-square
75-
[npm-downloads-href]: https://npmjs.com/package/nuxt-segment-analytics
74+
[npm-version-src]: https://img.shields.io/npm/dt/nuxt-segment.svg?style=flat-square
75+
[npm-version-href]: https://npmjs.com/package/nuxt-segment
76+
[npm-downloads-src]: https://img.shields.io/npm/v/nuxt-segment/latest.svg?style=flat-square
77+
[npm-downloads-href]: https://npmjs.com/package/nuxt-segment

lib/module.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
const { resolve } = require('path')
22

33
export default function (moduleOptions) {
4-
const options = Object.assign({ id: '', useRouter: true }, this.options.analytics, moduleOptions)
5-
this.addPlugin({
4+
const options = Object.assign(
5+
{
6+
sourceId: process.env.SEGMENT_SOURCE_ID || '',
7+
useRouter: process.env.SEGMENT_USE_ROUTER || true
8+
},
9+
this.options.segment,
10+
moduleOptions
11+
)
12+
13+
const pluginOpts = {
614
src: resolve(__dirname, 'plugin.js'),
7-
fileName: 'module.js',
15+
fileName: 'segment/plugin.js',
816
ssr: false,
9-
options: options
10-
})
11-
}
17+
options
18+
}
1219

13-
module.exports.meta = require('../package.json')
20+
this.addPlugin(pluginOpts)
21+
}

lib/plugin.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import Vue from 'vue'
22
import VueSegmentAnalytics from 'vue-segment-analytics'
33

4-
export default function (context) {
5-
const options = <%= JSON.stringify(options) %>
6-
const router = options.useRouter && context.app ? context.app.router : undefined
7-
Vue.use(VueSegmentAnalytics, {
8-
id: options.id,
9-
router: router
10-
})
11-
Vue.prototype.$analytics = window.analytics
4+
const SEGMENT_SOURCE_ID = '<%= options.sourceId %>'
5+
const SEGMENT_USE_ROUTER = <%= options.useRouter %>
6+
7+
export default function ({ app }) {
8+
9+
const options = {
10+
id: SEGMENT_SOURCE_ID
11+
}
12+
13+
if (SEGMENT_USE_ROUTER) {
14+
options.router = app.router;
15+
}
16+
17+
Vue.use(VueSegmentAnalytics, options)
18+
19+
Vue.prototype.$segment = window.analytics
1220
}

package.json

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
{
2-
"name": "nuxt-segment-analytics",
3-
"version": "0.0.1",
2+
"name": "nuxt-segment",
3+
"version": "0.0.0",
44
"description": "NuxtJS module for Segment Analytics.js",
55
"license": "MIT",
66
"contributors": [
77
{
8-
"name": "Dylan Wight <dylan@otechie.com>"
8+
"name": "Dylan Wight",
9+
"email": "dylan@otechie.com"
10+
},
11+
{
12+
"name": "Gaël Reyrol",
13+
"email": "gael@dansmaculotte.fr"
914
}
1015
],
1116
"main": "lib/module.js",
12-
"repository": "https://github.com/https://github.com/dgwight/nuxt-segment-analytics",
17+
"repository": "https://github.com/dansmaculotte/nuxt-segment",
1318
"publishConfig": {
1419
"access": "public"
1520
},
1621
"scripts": {
17-
"dev": "nuxt example",
22+
"dev": "nuxt test/fixture",
1823
"lint": "eslint lib test",
1924
"test": "yarn run lint && jest",
2025
"release": "standard-version && git push --follow-tags && npm publish"
@@ -33,20 +38,20 @@
3338
"vue-segment-analytics": "^0.3.1"
3439
},
3540
"devDependencies": {
36-
"babel-eslint": "latest",
37-
"codecov": "latest",
41+
"babel-eslint": "^10.0.1",
42+
"codecov": "^3.3.0",
3843
"dotenv": "^6.1.0",
39-
"eslint": "latest",
40-
"eslint-config-standard": "latest",
41-
"eslint-plugin-import": "latest",
42-
"eslint-plugin-jest": "latest",
43-
"eslint-plugin-node": "latest",
44-
"eslint-plugin-promise": "latest",
45-
"eslint-plugin-standard": "latest",
46-
"eslint-plugin-vue": "latest",
47-
"jest": "latest",
48-
"jsdom": "latest",
49-
"nuxt-edge": "latest",
50-
"standard-version": "latest"
44+
"eslint": "^5.16.0",
45+
"eslint-config-standard": "^12.0.0",
46+
"eslint-plugin-import": "^2.16.0",
47+
"eslint-plugin-jest": "^22.4.1",
48+
"eslint-plugin-node": "^8.0.1",
49+
"eslint-plugin-promise": "^4.1.1",
50+
"eslint-plugin-standard": "^4.0.0",
51+
"eslint-plugin-vue": "^5.2.2",
52+
"jest": "^24.7.1",
53+
"jsdom": "^14.0.0",
54+
"nuxt-edge": "^2.6.0-25905610.75e8a893",
55+
"standard-version": "^5.0.2"
5156
}
5257
}

example/nuxt.config.js test/fixture/nuxt.config.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ require('dotenv').config()
22
const { resolve } = require('path')
33

44
module.exports = {
5-
rootDir: resolve(__dirname, '..'),
5+
rootDir: resolve(__dirname, '../..'),
66
buildDIr: resolve(__dirname, '.nuxt'),
77
srcDir: __dirname,
88
render: {
99
resourceHints: false
1010
},
11-
modules: [
12-
'@@'
13-
],
14-
analytics: {
15-
id: process.env.SEGMENT_KEY,
16-
useRouter: false
17-
}
11+
modules: ['@@']
1812
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<template>
22
<div>
3-
Test
3+
Works!
44
</div>
55
</template>
66

77
<script>
88
export default {
99
mounted () {
10-
this.$analytics.identify('f4ca124298', {
10+
this.$segment.identify('f4ca124298', {
1111
name: 'Michael Bolton',
1212
email: 'mbolton@initech.com'
1313
})
14-
this.$analytics.track('Signed Up', { plan: 'Enterprise' })
15-
this.$analytics.page()
14+
this.$segment.track('Signed Up', { plan: 'Enterprise' })
15+
this.$segment.page()
1616
}
1717
}
1818
</script>

test/module.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { Nuxt, Builder } = require('nuxt-edge')
22
const request = require('request-promise-native')
33

4-
const config = require('../example/nuxt.config')
4+
const config = require('./fixture/nuxt.config')
55

66
const url = path => `http://localhost:3000${path}`
77
const get = path => request(url(path))
@@ -10,7 +10,6 @@ describe('basic', () => {
1010
let nuxt
1111

1212
beforeAll(async () => {
13-
config.dev = false
1413
nuxt = new Nuxt(config)
1514
await new Builder(nuxt).build()
1615
await nuxt.listen(3000)
@@ -22,6 +21,6 @@ describe('basic', () => {
2221

2322
test('render', async () => {
2423
let html = await get('/')
25-
expect(html).toContain('Test')
24+
expect(html).toContain('Works!')
2625
})
2726
})

0 commit comments

Comments
 (0)