Skip to content

Commit b795fbd

Browse files
authored
Merge branch 'main' into add_option_to_disable_data_collection
2 parents f58179e + 2bc8724 commit b795fbd

File tree

11 files changed

+263
-48
lines changed

11 files changed

+263
-48
lines changed

.envrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="
2+
3+
use devenv

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
node-version: [16, 18]
14+
node-version: [18, 20]
1515

1616
steps:
1717
- name: Checkout code

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ coverage
5454
Network Trash Folder
5555
Temporary Items
5656
.apdisk
57+
# Devenv
58+
.devenv*
59+
devenv.local.nix
60+
61+
# direnv
62+
.direnv
63+
64+
# pre-commit
65+
.pre-commit-config.yaml

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,25 @@ That's it! You can now use Nuxt UTM in your Nuxt app ✨
5353

5454
## Usage
5555

56+
You can use ```useNuxtUTM``` composable to access the UTM object:
57+
58+
```vue
59+
<script setup>
60+
const utm = useNuxtUTM();
61+
</script>
62+
```
63+
> Remember: You don't need to import the composable because nuxt imports it automatically.
64+
65+
Alternatively, you can get the UTM information through the Nuxt App with the following instructions:
66+
5667
```vue
5768
<script setup>
5869
import { useNuxtApp } from "nuxt/app";
5970
const { $utm } = useNuxtApp();
6071
</script>
6172
```
6273

63-
The `$utm` will contain an array of UTM parameters collected for use. Each element in the array represents a set of UTM parameters collected from a URL visit, and is structured as follows:
74+
Regardless of the option you choose to use the module, the `utm' object will contain an array of UTM parameters collected for use. Each element in the array represents a set of UTM parameters collected from a URL visit, and is structured as follows
6475

6576
```js
6677
[
@@ -93,6 +104,10 @@ In the `$utm` array, each entry provides a `timestamp` indicating when the UTM p
93104

94105
## Development
95106

107+
### Devenv
108+
109+
You can take advantage of [devenv.sh](https://devenv.sh) to quickly create the development environment for this this project. Use it in combination with [direnv](https://direnv.net/) to quickly load all the environment while navigating into the project directory in your shell.
110+
96111
```bash
97112
# Install dependencies
98113
yarn install

devenv.lock

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1726826452,
7+
"owner": "cachix",
8+
"repo": "devenv",
9+
"rev": "2bdf6461e88c7e93b94d72d8b11d5a61f167cbf5",
10+
"type": "github"
11+
},
12+
"original": {
13+
"dir": "src/modules",
14+
"owner": "cachix",
15+
"repo": "devenv",
16+
"type": "github"
17+
}
18+
},
19+
"flake-compat": {
20+
"flake": false,
21+
"locked": {
22+
"lastModified": 1696426674,
23+
"owner": "edolstra",
24+
"repo": "flake-compat",
25+
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
26+
"type": "github"
27+
},
28+
"original": {
29+
"owner": "edolstra",
30+
"repo": "flake-compat",
31+
"type": "github"
32+
}
33+
},
34+
"gitignore": {
35+
"inputs": {
36+
"nixpkgs": [
37+
"pre-commit-hooks",
38+
"nixpkgs"
39+
]
40+
},
41+
"locked": {
42+
"lastModified": 1709087332,
43+
"owner": "hercules-ci",
44+
"repo": "gitignore.nix",
45+
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
46+
"type": "github"
47+
},
48+
"original": {
49+
"owner": "hercules-ci",
50+
"repo": "gitignore.nix",
51+
"type": "github"
52+
}
53+
},
54+
"nixpkgs": {
55+
"locked": {
56+
"lastModified": 1716977621,
57+
"owner": "cachix",
58+
"repo": "devenv-nixpkgs",
59+
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
60+
"type": "github"
61+
},
62+
"original": {
63+
"owner": "cachix",
64+
"ref": "rolling",
65+
"repo": "devenv-nixpkgs",
66+
"type": "github"
67+
}
68+
},
69+
"nixpkgs-stable": {
70+
"locked": {
71+
"lastModified": 1726838390,
72+
"owner": "NixOS",
73+
"repo": "nixpkgs",
74+
"rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101",
75+
"type": "github"
76+
},
77+
"original": {
78+
"owner": "NixOS",
79+
"ref": "nixos-24.05",
80+
"repo": "nixpkgs",
81+
"type": "github"
82+
}
83+
},
84+
"pre-commit-hooks": {
85+
"inputs": {
86+
"flake-compat": "flake-compat",
87+
"gitignore": "gitignore",
88+
"nixpkgs": [
89+
"nixpkgs"
90+
],
91+
"nixpkgs-stable": "nixpkgs-stable"
92+
},
93+
"locked": {
94+
"lastModified": 1726745158,
95+
"owner": "cachix",
96+
"repo": "pre-commit-hooks.nix",
97+
"rev": "4e743a6920eab45e8ba0fbe49dc459f1423a4b74",
98+
"type": "github"
99+
},
100+
"original": {
101+
"owner": "cachix",
102+
"repo": "pre-commit-hooks.nix",
103+
"type": "github"
104+
}
105+
},
106+
"root": {
107+
"inputs": {
108+
"devenv": "devenv",
109+
"nixpkgs": "nixpkgs",
110+
"pre-commit-hooks": "pre-commit-hooks"
111+
}
112+
}
113+
},
114+
"root": "root",
115+
"version": 7
116+
}

devenv.nix

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ pkgs, lib, config, inputs, ... }:
2+
3+
{
4+
packages = [ pkgs.git ];
5+
6+
languages.javascript = {
7+
enable = true;
8+
yarn.enable = true;
9+
};
10+
11+
enterShell = ''
12+
git --version
13+
node --version
14+
yarn install
15+
'';
16+
17+
pre-commit.hooks.eslint.enable = true;
18+
}

devenv.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
2+
inputs:
3+
nixpkgs:
4+
url: github:cachix/devenv-nixpkgs/rolling
5+
6+
# If you're using non-OSS software, you can set allowUnfree to true.
7+
# allowUnfree: true
8+
9+
# If you're willing to use a package that's vulnerable
10+
# permittedInsecurePackages:
11+
# - "openssl-1.1.1w"
12+
13+
# If you have more than one devenv you can merge them
14+
#imports:
15+
# - ./backend

playground/app.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div>Nuxt 3 UTM module playground!</div>
3-
<pre>{{ $utm }}</pre>
3+
<pre>{{ utm }}</pre>
44
</template>
55

66
<script setup>
7-
import { useNuxtApp } from "nuxt/app";
7+
import { useNuxtUTM } from '#imports';
88
9-
const { $utm } = useNuxtApp();
9+
const utm = useNuxtUTM();
1010
</script>

src/module.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineNuxtModule, addPlugin, createResolver } from "@nuxt/kit";
1+
import { defineNuxtModule, addPlugin, addImports, createResolver } from "@nuxt/kit";
22

33
export interface ModuleOptions {
44
enabled: boolean;
@@ -18,6 +18,10 @@ export default defineNuxtModule<ModuleOptions>({
1818
if (options.enabled) {
1919
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
2020
addPlugin(resolver.resolve("./runtime/plugin"));
21+
addImports({
22+
name: 'useNuxtUTM',
23+
from: resolver.resolve('runtime/composables'),
24+
})
2125
}
2226
},
2327
});

src/runtime/composables.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useNuxtApp } from '#imports'
2+
3+
export const useNuxtUTM = () => {
4+
const nuxtApp = useNuxtApp()
5+
return nuxtApp.$utm
6+
}

0 commit comments

Comments
 (0)