Skip to content

Commit

Permalink
Merge branch 'main' into add_option_to_disable_data_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
sadjow authored Oct 24, 2024
2 parents f58179e + 2bc8724 commit b795fbd
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0="

use devenv
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [16, 18]
node-version: [18, 20]

steps:
- name: Checkout code
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ coverage
Network Trash Folder
Temporary Items
.apdisk
# Devenv
.devenv*
devenv.local.nix

# direnv
.direnv

# pre-commit
.pre-commit-config.yaml
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ That's it! You can now use Nuxt UTM in your Nuxt app ✨

## Usage

You can use ```useNuxtUTM``` composable to access the UTM object:

```vue
<script setup>
const utm = useNuxtUTM();
</script>
```
> Remember: You don't need to import the composable because nuxt imports it automatically.
Alternatively, you can get the UTM information through the Nuxt App with the following instructions:

```vue
<script setup>
import { useNuxtApp } from "nuxt/app";
const { $utm } = useNuxtApp();
</script>
```

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:
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

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

## Development

### Devenv

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.

```bash
# Install dependencies
yarn install
Expand Down
116 changes: 116 additions & 0 deletions devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1726826452,
"owner": "cachix",
"repo": "devenv",
"rev": "2bdf6461e88c7e93b94d72d8b11d5a61f167cbf5",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1726838390,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1726745158,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "4e743a6920eab45e8ba0fbe49dc459f1423a4b74",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}
18 changes: 18 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ pkgs, lib, config, inputs, ... }:

{
packages = [ pkgs.git ];

languages.javascript = {
enable = true;
yarn.enable = true;
};

enterShell = ''
git --version
node --version
yarn install
'';

pre-commit.hooks.eslint.enable = true;
}
15 changes: 15 additions & 0 deletions devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling

# If you're using non-OSS software, you can set allowUnfree to true.
# allowUnfree: true

# If you're willing to use a package that's vulnerable
# permittedInsecurePackages:
# - "openssl-1.1.1w"

# If you have more than one devenv you can merge them
#imports:
# - ./backend
6 changes: 3 additions & 3 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div>Nuxt 3 UTM module playground!</div>
<pre>{{ $utm }}</pre>
<pre>{{ utm }}</pre>
</template>

<script setup>
import { useNuxtApp } from "nuxt/app";
import { useNuxtUTM } from '#imports';
const { $utm } = useNuxtApp();
const utm = useNuxtUTM();
</script>
6 changes: 5 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtModule, addPlugin, createResolver } from "@nuxt/kit";
import { defineNuxtModule, addPlugin, addImports, createResolver } from "@nuxt/kit";

export interface ModuleOptions {
enabled: boolean;
Expand All @@ -18,6 +18,10 @@ export default defineNuxtModule<ModuleOptions>({
if (options.enabled) {
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve("./runtime/plugin"));
addImports({
name: 'useNuxtUTM',
from: resolver.resolve('runtime/composables'),
})
}
},
});
6 changes: 6 additions & 0 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useNuxtApp } from '#imports'

export const useNuxtUTM = () => {
const nuxtApp = useNuxtApp()
return nuxtApp.$utm
}
Loading

0 comments on commit b795fbd

Please sign in to comment.