feeds-fun 1.18.1 → 1.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feeds-fun",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "author": "Aliaksei Yaletski (Tiendil) <a.eletsky@gmail.com> (https://tiendil.org/)",
5
5
  "description": "Frontend for the Feeds Fun — web-based news reader",
6
6
  "keywords": [
@@ -36,12 +36,12 @@
36
36
  "@vueuse/core": "^11.2.0",
37
37
  "axios": "^1.7.7",
38
38
  "dompurify": "^3.1.7",
39
+ "lodash": "^4.17.21",
39
40
  "pinia": "^2.2.6",
40
41
  "set-interval-async": "^3.0.3",
41
42
  "supertokens-web-js": "^0.5.0",
42
43
  "vue": "^3.5.12",
43
- "vue-router": "^4.4.5",
44
- "lodash": "^4.17.21"
44
+ "vue-router": "^4.4.5"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@rushstack/eslint-patch": "^1.10.4",
package/src/App.vue CHANGED
@@ -2,7 +2,31 @@
2
2
  <router-view />
3
3
  </template>
4
4
 
5
- <script setup lang="ts"></script>
5
+ <script setup lang="ts">
6
+ import {onMounted} from "vue";
7
+ import {watchEffect} from "vue";
8
+ import {useRoute, useRouter} from "vue-router";
9
+ import {StorageSerializers, useStorage} from "@vueuse/core";
10
+ import {useGlobalState} from "@/stores/globalState";
11
+ import * as marketing from "@/logic/marketing";
12
+ import * as events from "@/logic/events";
13
+
14
+ const route = useRoute();
15
+ const router = useRouter();
16
+ const utmStorage = useStorage("ffun_utm", null, undefined, {serializer: StorageSerializers.object});
17
+ const globalState = useGlobalState();
18
+
19
+ watchEffect(() => {
20
+ marketing.processUTM(route, router, utmStorage);
21
+ });
22
+
23
+ watchEffect(async () => {
24
+ if (utmStorage.value && globalState.isLoggedIn && Object.keys(utmStorage.value).length > 0) {
25
+ await events.trackUtm(utmStorage.value);
26
+ utmStorage.value = null;
27
+ }
28
+ });
29
+ </script>
6
30
 
7
31
  <style scoped>
8
32
  .container {
package/src/logic/api.ts CHANGED
@@ -2,6 +2,7 @@ import * as _ from "lodash";
2
2
  import axios, {AxiosError} from "axios";
3
3
  import * as t from "@/logic/types";
4
4
  import type * as e from "@/logic/enums";
5
+ import * as settings from "@/logic/settings";
5
6
 
6
7
  const ENTRY_POINT = "/api";
7
8
 
@@ -331,5 +332,9 @@ export async function getInfo() {
331
332
  }
332
333
 
333
334
  export async function trackEvent(data: {[key: string]: string | number | null}) {
335
+ if (!settings.trackEvents) {
336
+ return;
337
+ }
338
+
334
339
  await post({url: API_TRACK_EVENT, data: {event: data}});
335
340
  }
@@ -83,3 +83,20 @@ export async function tagStateChanged({
83
83
  source: source
84
84
  });
85
85
  }
86
+
87
+ export async function trackUtm({
88
+ utm_source,
89
+ utm_medium,
90
+ utm_campaign
91
+ }: {
92
+ utm_source: string;
93
+ utm_medium: string;
94
+ utm_campaign: string;
95
+ }) {
96
+ await api.trackEvent({
97
+ name: "user_utm",
98
+ utm_source: utm_source,
99
+ utm_medium: utm_medium,
100
+ utm_campaign: utm_campaign
101
+ });
102
+ }
@@ -0,0 +1,54 @@
1
+ import {useRoute, useRouter} from "vue-router";
2
+ import type {RouteLocationNormalizedLoaded, Router} from "vue-router";
3
+ import * as settings from "@/logic/settings";
4
+
5
+ export function processUTM(route: RouteLocationNormalizedLoaded, router: Router, utmStorage: any) {
6
+ const utmParams = ["utm_source", "utm_medium", "utm_campaign"];
7
+
8
+ // extract UTM parameters from the URL
9
+ const utmData = utmParams.reduce(
10
+ (acc, param) => {
11
+ const value = route.query[param];
12
+
13
+ if (!value) {
14
+ return acc;
15
+ }
16
+
17
+ if (Array.isArray(value)) {
18
+ if (value[0]) {
19
+ acc[param] = value[0];
20
+ }
21
+
22
+ return acc;
23
+ }
24
+
25
+ if (value) {
26
+ acc[param] = value;
27
+ return acc;
28
+ }
29
+
30
+ return acc;
31
+ },
32
+ {} as Record<string, string>
33
+ );
34
+
35
+ // remove UTM parameters from the URL if they exist
36
+ if (Object.keys(utmData).length > 0) {
37
+ const newQuery = {...route.query};
38
+
39
+ utmParams.forEach((param) => {
40
+ if (newQuery[param]) {
41
+ delete newQuery[param];
42
+ }
43
+ });
44
+
45
+ router.replace({query: newQuery});
46
+ }
47
+
48
+ // store UTM in local storage
49
+ if (Object.keys(utmData).length == 0) {
50
+ return;
51
+ }
52
+
53
+ utmStorage.value = utmData;
54
+ }
@@ -22,6 +22,10 @@ export const plausibleEnabled = import.meta.env.VITE_FFUN_PLAUSIBLE_ENABLED == "
22
22
  export const plausibleDomain = import.meta.env.VITE_FFUN_PLAUSIBLE_DOMAIN || "localhost";
23
23
  export const plausibleScript = import.meta.env.VITE_FFUN_PLAUSIBLE_SCRIPT || "";
24
24
 
25
+ export const trackEvents = import.meta.env.VITE_FFUN_TRACK_EVENTS == "true" || false;
26
+
27
+ export const utmLifetime = import.meta.env.VITE_FFUN_UTM_LIFETIME || 7; // days
28
+
25
29
  console.log("settings.appName", appName);
26
30
  console.log("settings.appDomain", appDomain);
27
31
  console.log("settings.appPort", appPort);
@@ -40,3 +44,7 @@ console.log("settings.redditSubreddit", redditSubreddit);
40
44
  console.log("settings.plausibleEnabled", plausibleEnabled);
41
45
  console.log("settings.plausibleDomain", plausibleDomain);
42
46
  console.log("settings.plausibleScript", plausibleScript);
47
+
48
+ console.log("settings.trackEvents", trackEvents);
49
+
50
+ console.log("settings.utmLifetime", utmLifetime);