Skip to content

Commit ace871f

Browse files
committed
initial
0 parents  commit ace871f

13 files changed

+9928
-0
lines changed

.circleci/config.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: /usr/src/app
5+
docker:
6+
- image: banian/node
7+
steps:
8+
# Checkout repository
9+
- checkout
10+
11+
# Restore cache
12+
- restore_cache:
13+
key: yarn-{{ checksum "yarn.lock" }}
14+
15+
# Install dependencies
16+
- run:
17+
name: Install Dependencies
18+
command: NODE_ENV=dev yarn
19+
20+
# Keep cache
21+
- save_cache:
22+
key: yarn-{{ checksum "yarn.lock" }}
23+
paths:
24+
- "node_modules"
25+
26+
# Test
27+
- run:
28+
name: Tests
29+
command: yarn test
30+
31+
# Coverage
32+
- run:
33+
name: Coverage
34+
command: yarn codecov

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

.eslintrc.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root: true
2+
parserOptions:
3+
parser: babel-eslint
4+
env:
5+
browser: true
6+
node: true
7+
jest: true
8+
extends:
9+
- standard
10+
- plugin:vue/recommended
11+
plugins:
12+
- jest
13+
- vue
14+
rules:
15+
arrow-parens: 0
16+
generator-star-spacing: 0
17+
no-console: 2
18+
globals:
19+
jest/globals: true
20+
jasmine: true

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
*.iml
3+
.idea
4+
*.log*
5+
.nuxt
6+
.vscode
7+
.DS_Store
8+
coverage
9+
dist
10+
.env

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Dylan Wight <dylan@otechie.com>
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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# nuxt-segment-analytics
2+
3+
[![David-DM][david-dm-src]][david-dm-href]
4+
[![Standard JS][standard-js-src]][standard-js-href]
5+
[![Circle CI][circle-ci-src]][circle-ci-href]
6+
[![Codecov][codecov-src]][codecov-href]
7+
[![npm version][npm-version-src]][npm-version-href]
8+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
9+
10+
> NuxtJS module for Stripe.js
11+
12+
[📖 **Release Notes**](./CHANGELOG.md)
13+
14+
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()
16+
17+
## Setup
18+
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`
21+
22+
## Usage
23+
### nuxt.config.js
24+
```js
25+
{
26+
modules: [
27+
// Simple usage
28+
'nuxt-segment-analytics',
29+
30+
// With options
31+
['nuxt-segment-analytics', { id: "SEGMENT_KEY", useRouter: true }],
32+
]
33+
}
34+
```
35+
36+
### YourComponent.vue
37+
```js
38+
export default {
39+
mounted () {
40+
this.$analytics.identify('f4ca124298', {
41+
name: 'Michael Bolton',
42+
email: 'mbolton@initech.com'
43+
})
44+
this.$analytics.track('Signed Up', { plan: 'Enterprise' })
45+
this.$analytics.page('Pricing');
46+
}
47+
}
48+
```
49+
50+
51+
## Development
52+
53+
- Clone this repository
54+
- Install dependencies using `yarn install` or `npm install`
55+
- Start development server using `npm run dev`
56+
57+
## License
58+
59+
[MIT License](./LICENSE)
60+
61+
Copyright (c) Dylan Wight <dylan@otechie.com>
62+
63+
<!-- 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
66+
[standard-js-src]: https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square
67+
[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

example/nuxt.config.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require('dotenv').config()
2+
const { resolve } = require('path')
3+
4+
module.exports = {
5+
rootDir: resolve(__dirname, '..'),
6+
buildDIr: resolve(__dirname, '.nuxt'),
7+
srcDir: __dirname,
8+
render: {
9+
resourceHints: false
10+
},
11+
modules: [
12+
'@@'
13+
],
14+
analytics: {
15+
id: process.env.SEGMENT_KEY,
16+
useRouter: false
17+
}
18+
}

example/pages/index.vue

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div>
3+
Test
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
mounted () {
10+
this.$analytics.identify('f4ca124298', {
11+
name: 'Michael Bolton',
12+
email: 'mbolton@initech.com'
13+
})
14+
this.$analytics.track('Signed Up', { plan: 'Enterprise' })
15+
this.$analytics.page()
16+
}
17+
}
18+
</script>

lib/module.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { resolve } = require('path')
2+
3+
export default function (moduleOptions) {
4+
const options = Object.assign({ id: '', useRouter: true }, this.options.analytics, moduleOptions)
5+
this.addPlugin({
6+
src: resolve(__dirname, 'plugin.js'),
7+
fileName: 'module.js',
8+
ssr: false,
9+
options: options
10+
})
11+
}
12+
13+
module.exports.meta = require('../package.json')

lib/plugin.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vue from 'vue'
2+
import VueSegmentAnalytics from 'vue-segment-analytics'
3+
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
12+
}

package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "nuxt-segment-analytics",
3+
"version": "0.0.0",
4+
"description": "NuxtJS module for Segment Analytics.js",
5+
"license": "MIT",
6+
"contributors": [
7+
{
8+
"name": "Dylan Wight <dylan@otechie.com>"
9+
}
10+
],
11+
"main": "lib/module.js",
12+
"repository": "https://github.com/https://github.com/dgwight/nuxt-segment-analytics",
13+
"publishConfig": {
14+
"access": "public"
15+
},
16+
"scripts": {
17+
"dev": "nuxt example",
18+
"lint": "eslint lib test",
19+
"test": "yarn run lint && jest",
20+
"release": "standard-version && git push --follow-tags && npm publish"
21+
},
22+
"eslintIgnore": [
23+
"lib/plugin.js"
24+
],
25+
"files": [
26+
"lib"
27+
],
28+
"jest": {
29+
"testEnvironment": "node",
30+
"collectCoverage": true
31+
},
32+
"dependencies": {
33+
"vue-segment-analytics": "^0.3.1"
34+
},
35+
"devDependencies": {
36+
"babel-eslint": "latest",
37+
"codecov": "latest",
38+
"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"
51+
}
52+
}

test/module.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { Nuxt, Builder } = require('nuxt-edge')
2+
const request = require('request-promise-native')
3+
4+
const config = require('../example/nuxt.config')
5+
6+
const url = path => `http://localhost:3000${path}`
7+
const get = path => request(url(path))
8+
9+
describe('basic', () => {
10+
let nuxt
11+
12+
beforeAll(async () => {
13+
config.dev = false
14+
nuxt = new Nuxt(config)
15+
await new Builder(nuxt).build()
16+
await nuxt.listen(3000)
17+
}, 60000)
18+
19+
afterAll(async () => {
20+
await nuxt.close()
21+
})
22+
23+
test('render', async () => {
24+
let html = await get('/')
25+
expect(html).toContain('Test')
26+
})
27+
})

0 commit comments

Comments
 (0)