@unproducts/nuxt-posthog 2.0.6 → 2.0.7
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/dist/module.json +1 -1
- package/dist/module.mjs +1 -22
- package/dist/runtime/plugins/posthog.client.js +3 -4
- package/dist/runtime/types/index.d.ts +9 -0
- package/package.json +1 -1
- package/dist/runtime/components/PostHogFeatureFlag.d.vue.ts +0 -37
- package/dist/runtime/components/PostHogFeatureFlag.vue +0 -14
- package/dist/runtime/components/PostHogFeatureFlag.vue.d.ts +0 -37
- package/dist/runtime/composables/usePostHogFeatureFlag.d.ts +0 -9
- package/dist/runtime/composables/usePostHogFeatureFlag.js +0 -18
- package/dist/runtime/directives/v-posthog-capture.d.ts +0 -2
- package/dist/runtime/directives/v-posthog-capture.js +0 -17
- package/dist/runtime/plugins/directives.d.ts +0 -2
- package/dist/runtime/plugins/directives.js +0 -5
- package/dist/runtime/plugins/nitro.d.ts +0 -2
- package/dist/runtime/plugins/nitro.js +0 -11
- package/dist/runtime/plugins/posthog.server.d.ts +0 -7
- package/dist/runtime/plugins/posthog.server.js +0 -31
- package/dist/runtime/types/directives.d.ts +0 -27
- package/dist/runtime/types/nitro.d.ts +0 -7
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPlugin,
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, addServerImports } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const module$1 = defineNuxtModule({
|
|
@@ -55,34 +55,13 @@ const module$1 = defineNuxtModule({
|
|
|
55
55
|
proxy: `https://${region}.i.posthog.com/**`
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
nuxt.hook("imports:dirs", (dirs) => {
|
|
59
|
-
dirs.push(resolve("./runtime/composables"));
|
|
60
|
-
});
|
|
61
|
-
addPlugin(resolve("./runtime/plugins/directives"));
|
|
62
58
|
addPlugin(resolve("./runtime/plugins/posthog.client"));
|
|
63
|
-
addPlugin(resolve("./runtime/plugins/posthog.server"));
|
|
64
|
-
addComponent({
|
|
65
|
-
filePath: resolve("./runtime/components/PostHogFeatureFlag.vue"),
|
|
66
|
-
name: "PostHogFeatureFlag"
|
|
67
|
-
});
|
|
68
|
-
addTypeTemplate({
|
|
69
|
-
filename: "types/posthog-directives.d.ts",
|
|
70
|
-
src: resolve("./runtime/types/directives.d.ts")
|
|
71
|
-
});
|
|
72
|
-
addServerPlugin(resolve("./runtime/plugins/nitro"));
|
|
73
59
|
addServerImports([
|
|
74
60
|
{
|
|
75
61
|
from: resolve("./runtime/utils/nitro"),
|
|
76
62
|
name: "usePostHog"
|
|
77
63
|
}
|
|
78
64
|
]);
|
|
79
|
-
addTypeTemplate(
|
|
80
|
-
{
|
|
81
|
-
filename: "types/posthog-nitro.d.ts",
|
|
82
|
-
src: resolve("./runtime/types/nitro.d.ts")
|
|
83
|
-
},
|
|
84
|
-
{ nitro: true }
|
|
85
|
-
);
|
|
86
65
|
}
|
|
87
66
|
});
|
|
88
67
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineNuxtPlugin,
|
|
1
|
+
import { defineNuxtPlugin, useRouter, useRuntimeConfig, useState } from "#app";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "posthog",
|
|
5
5
|
enforce: "post",
|
|
6
|
-
setup: async () => {
|
|
6
|
+
setup: async (nuxtApp) => {
|
|
7
7
|
const config = useRuntimeConfig().public.posthog;
|
|
8
8
|
if (!config?.client)
|
|
9
9
|
return {
|
|
@@ -36,8 +36,7 @@ export default defineNuxtPlugin({
|
|
|
36
36
|
clientOptions.api_host = `${window.location.origin}/ingest/ph`;
|
|
37
37
|
}
|
|
38
38
|
const posthogClient = posthog.init(config.key, clientOptions);
|
|
39
|
-
|
|
40
|
-
identity.value = posthog.get_distinct_id();
|
|
39
|
+
nuxtApp.callHook("posthog:init", posthogClient);
|
|
41
40
|
if (config.capturePageViews) {
|
|
42
41
|
const router = useRouter();
|
|
43
42
|
router.afterEach((to) => {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ModuleOptions } from '../../module';
|
|
2
|
+
import type { HookResult } from 'nuxt/schema';
|
|
3
|
+
import type { PostHog } from 'posthog-js';
|
|
2
4
|
|
|
3
5
|
declare module '@nuxt/schema' {
|
|
4
6
|
/** Server-only config (private). Key/host live in public only; Nitro usePostHog reads serverOptions here. */
|
|
@@ -18,3 +20,10 @@ declare module '@nuxt/schema' {
|
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
}
|
|
23
|
+
|
|
24
|
+
declare module '#app' {
|
|
25
|
+
/** Custom runtime hook used by nuxtApp.hook('posthog:init', ...) */
|
|
26
|
+
interface RuntimeNuxtHooks {
|
|
27
|
+
'posthog:init': (posthog: PostHog | null) => HookResult;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
declare var __VLS_1: {
|
|
2
|
-
payload: any;
|
|
3
|
-
};
|
|
4
|
-
type __VLS_Slots = {} & {
|
|
5
|
-
default?: (props: typeof __VLS_1) => any;
|
|
6
|
-
};
|
|
7
|
-
declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
8
|
-
name: {
|
|
9
|
-
type: StringConstructor;
|
|
10
|
-
required: true;
|
|
11
|
-
};
|
|
12
|
-
match: {
|
|
13
|
-
default: boolean;
|
|
14
|
-
required: false;
|
|
15
|
-
type: (StringConstructor | BooleanConstructor)[];
|
|
16
|
-
};
|
|
17
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
18
|
-
name: {
|
|
19
|
-
type: StringConstructor;
|
|
20
|
-
required: true;
|
|
21
|
-
};
|
|
22
|
-
match: {
|
|
23
|
-
default: boolean;
|
|
24
|
-
required: false;
|
|
25
|
-
type: (StringConstructor | BooleanConstructor)[];
|
|
26
|
-
};
|
|
27
|
-
}>> & Readonly<{}>, {
|
|
28
|
-
match: string | boolean;
|
|
29
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
30
|
-
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
31
|
-
declare const _default: typeof __VLS_export;
|
|
32
|
-
export default _default;
|
|
33
|
-
type __VLS_WithSlots<T, S> = T & {
|
|
34
|
-
new (): {
|
|
35
|
-
$slots: S;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { computed } from "vue";
|
|
3
|
-
import usePostHogFeatureFlag from "../composables/usePostHogFeatureFlag";
|
|
4
|
-
const { name, match } = defineProps({
|
|
5
|
-
name: { type: String, required: true },
|
|
6
|
-
match: { default: true, required: false, type: [String, Boolean] }
|
|
7
|
-
});
|
|
8
|
-
const { getFeatureFlag } = usePostHogFeatureFlag();
|
|
9
|
-
const featureFlag = computed(() => getFeatureFlag(name));
|
|
10
|
-
</script>
|
|
11
|
-
|
|
12
|
-
<template>
|
|
13
|
-
<slot v-if="featureFlag?.value === match" :payload="featureFlag.payload" />
|
|
14
|
-
</template>
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
declare var __VLS_1: {
|
|
2
|
-
payload: any;
|
|
3
|
-
};
|
|
4
|
-
type __VLS_Slots = {} & {
|
|
5
|
-
default?: (props: typeof __VLS_1) => any;
|
|
6
|
-
};
|
|
7
|
-
declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
8
|
-
name: {
|
|
9
|
-
type: StringConstructor;
|
|
10
|
-
required: true;
|
|
11
|
-
};
|
|
12
|
-
match: {
|
|
13
|
-
default: boolean;
|
|
14
|
-
required: false;
|
|
15
|
-
type: (StringConstructor | BooleanConstructor)[];
|
|
16
|
-
};
|
|
17
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
18
|
-
name: {
|
|
19
|
-
type: StringConstructor;
|
|
20
|
-
required: true;
|
|
21
|
-
};
|
|
22
|
-
match: {
|
|
23
|
-
default: boolean;
|
|
24
|
-
required: false;
|
|
25
|
-
type: (StringConstructor | BooleanConstructor)[];
|
|
26
|
-
};
|
|
27
|
-
}>> & Readonly<{}>, {
|
|
28
|
-
match: string | boolean;
|
|
29
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
30
|
-
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
31
|
-
declare const _default: typeof __VLS_export;
|
|
32
|
-
export default _default;
|
|
33
|
-
type __VLS_WithSlots<T, S> = T & {
|
|
34
|
-
new (): {
|
|
35
|
-
$slots: S;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useState } from "#app";
|
|
2
|
-
export default () => {
|
|
3
|
-
const posthogFeatureFlags = useState("ph-feature-flags");
|
|
4
|
-
const posthogFeatureFlagPayloads = useState("ph-feature-flag-payloads");
|
|
5
|
-
const isFeatureEnabled = (feature) => {
|
|
6
|
-
return posthogFeatureFlags.value?.[feature] ?? false;
|
|
7
|
-
};
|
|
8
|
-
const getFeatureFlag = (feature) => {
|
|
9
|
-
return {
|
|
10
|
-
value: posthogFeatureFlags.value?.[feature] ?? false,
|
|
11
|
-
payload: posthogFeatureFlagPayloads.value?.[feature]
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
return {
|
|
15
|
-
isFeatureEnabled,
|
|
16
|
-
getFeatureFlag
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useNuxtApp } from "#app";
|
|
2
|
-
const directive = (el, { value, arg }) => {
|
|
3
|
-
const nuxtApp = useNuxtApp();
|
|
4
|
-
const $clientPosthog = nuxtApp.$clientPosthog;
|
|
5
|
-
if (!$clientPosthog) return;
|
|
6
|
-
if (el.hasAttribute("posthog-listener")) return;
|
|
7
|
-
el.setAttribute("posthog-listener", "true");
|
|
8
|
-
el.addEventListener(arg ?? "click", () => {
|
|
9
|
-
if (!$clientPosthog) return;
|
|
10
|
-
if (typeof value === "string") $clientPosthog.capture(value);
|
|
11
|
-
else $clientPosthog.capture(value.name, value.properties);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
export const vPostHogCapture = {
|
|
15
|
-
mounted: directive,
|
|
16
|
-
updated: directive
|
|
17
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
import { defineNitroPlugin } from "nitropack/runtime";
|
|
3
|
-
import { getCookie } from "h3";
|
|
4
|
-
export default defineNitroPlugin((nitroApp) => {
|
|
5
|
-
nitroApp.hooks.hook("request", async (event) => {
|
|
6
|
-
const config = useRuntimeConfig().public.posthog;
|
|
7
|
-
if (!config?.client) return;
|
|
8
|
-
const distinctId = getCookie(event, "ph-identify");
|
|
9
|
-
event.context.posthogId = distinctId;
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useCookie, useRuntimeConfig, useState } from "#app";
|
|
2
|
-
export default defineNuxtPlugin({
|
|
3
|
-
name: "posthog-server",
|
|
4
|
-
enforce: "post",
|
|
5
|
-
setup: async () => {
|
|
6
|
-
const publicConfig = useRuntimeConfig().public.posthog;
|
|
7
|
-
if (!publicConfig?.client)
|
|
8
|
-
return {
|
|
9
|
-
provide: {
|
|
10
|
-
serverPosthog: null
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
if (!publicConfig.key || !publicConfig.host) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"PostHog client (SSR) is enabled but key or host not found. Set client to false in module options to disable."
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
const PostHog = (await import("posthog-node")).PostHog;
|
|
19
|
-
const posthog = new PostHog(publicConfig.key, { host: publicConfig.host });
|
|
20
|
-
await posthog.reloadFeatureFlags();
|
|
21
|
-
const identity = useCookie("ph-identify", { default: () => "" });
|
|
22
|
-
const { featureFlags, featureFlagPayloads } = await posthog.getAllFlagsAndPayloads(identity.value);
|
|
23
|
-
useState("ph-feature-flags", () => featureFlags);
|
|
24
|
-
useState("ph-feature-flag-payloads", () => featureFlagPayloads);
|
|
25
|
-
return {
|
|
26
|
-
provide: {
|
|
27
|
-
serverPosthog: posthog
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ObjectDirective } from 'vue';
|
|
2
|
-
import type { Property } from 'posthog-js';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
export interface PostHogCaptureEvent {
|
|
6
|
-
/**
|
|
7
|
-
* Event name
|
|
8
|
-
*
|
|
9
|
-
* @docs https://posthog.com/docs/product-analytics/capture-events
|
|
10
|
-
*/
|
|
11
|
-
name: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Event properties
|
|
15
|
-
*
|
|
16
|
-
* @docs https://posthog.com/docs/product-analytics/capture-events#setting-event-properties
|
|
17
|
-
*/
|
|
18
|
-
properties?: Record<string, Property>;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare module 'vue' {
|
|
23
|
-
export interface ComponentCustomProperties {
|
|
24
|
-
vPosthogCapture: ObjectDirective<HTMLElement, PostHogCaptureEvent | string>;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export {};
|