Skip to content

Commit 2342f65

Browse files
authored
feat: Track visits even when UTM parameters are absent (#47)
1 parent f27517a commit 2342f65

File tree

8 files changed

+15
-173
lines changed

8 files changed

+15
-173
lines changed

.gitignore

-9
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,3 @@ 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

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![License][license-src]][license-href]
77
[![Nuxt][nuxt-src]][nuxt-href]
88

9-
**Built in collaboration with the Durst Organization**
9+
**Built in collaboration with The Durst Organization**
1010

1111
---
1212

@@ -109,10 +109,6 @@ In the `$utm` array, each entry provides a `timestamp` indicating when the UTM p
109109

110110
## Development
111111

112-
### Devenv
113-
114-
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.
115-
116112
```bash
117113
# Install dependencies
118114
yarn install

devenv.lock

-116
This file was deleted.

devenv.nix

-18
This file was deleted.

devenv.yaml

-15
This file was deleted.

src/runtime/plugin.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { DataObject } from "nuxt-utm";
22
import {
33
readLocalData,
44
getSessionID,
5-
urlHasUtmParams,
65
getUtmParams,
76
getAdditionalInfo,
87
isRepeatedEntry,
@@ -25,14 +24,8 @@ export default defineNuxtPlugin((nuxtApp) => {
2524
const sessionId = getSessionID(SESSION_ID_KEY);
2625

2726
const query = nuxtApp._route.query;
28-
29-
// Exit if no UTM parameters found
30-
if (!urlHasUtmParams(query)) return;
31-
3227
const utmParams = getUtmParams(query);
33-
3428
const additionalInfo = getAdditionalInfo();
35-
3629
const timestamp = new Date().toISOString();
3730

3831
const dataObject: DataObject = {
@@ -42,7 +35,7 @@ export default defineNuxtPlugin((nuxtApp) => {
4235
sessionId,
4336
};
4437

45-
if (urlHasGCLID) {
38+
if (urlHasGCLID(query)) {
4639
dataObject.gclidParams = getGCLID(query);
4740
}
4841

src/runtime/utm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const urlHasUtmParams = (query: LocationQuery): boolean => {
3535
query.utm_medium ||
3636
query.utm_campaign ||
3737
query.utm_term ||
38-
query.utm_content,
38+
query.utm_content
3939
);
4040
};
4141

@@ -75,7 +75,7 @@ export const getAdditionalInfo = (): AdditionalInfo => {
7575

7676
export const isRepeatedEntry = (
7777
data: Ref<DataObject[]>,
78-
currentEntry: DataObject,
78+
currentEntry: DataObject
7979
): boolean => {
8080
const lastEntry = data.value?.[0];
8181
const lastUtm = lastEntry?.utmParams;

test/unit.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ describe("getUtmParams function", () => {
6868
utm_content: "test_content",
6969
});
7070
});
71+
72+
it("Returns undefined values when no UTM params are present", () => {
73+
const locationQueryMock = {};
74+
expect(getUtmParams(locationQueryMock)).toEqual({
75+
utm_source: undefined,
76+
utm_medium: undefined,
77+
utm_campaign: undefined,
78+
utm_term: undefined,
79+
utm_content: undefined,
80+
});
81+
});
7182
});
7283

7384
describe("isRepeatedEntry function", () => {

0 commit comments

Comments
 (0)