@unproducts/nuxt-posthog 2.0.4 → 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.d.mts +10 -7
- package/dist/module.json +1 -1
- package/dist/module.mjs +25 -46
- package/dist/runtime/plugins/posthog.client.d.ts +2 -2
- package/dist/runtime/plugins/posthog.client.js +10 -8
- package/dist/runtime/types/index.d.ts +18 -2
- package/dist/runtime/utils/nitro.d.ts +1 -1
- package/dist/runtime/utils/nitro.js +11 -4
- package/package.json +3 -2
- 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 -12
- package/dist/runtime/plugins/posthog.server.d.ts +0 -7
- package/dist/runtime/plugins/posthog.server.js +0 -27
- package/dist/runtime/types/directives.d.ts +0 -27
- package/dist/runtime/types/nitro.d.ts +0 -7
package/dist/module.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { PostHogConfig } from 'posthog-js';
|
|
3
|
+
import { PostHogOptions } from 'posthog-node';
|
|
3
4
|
|
|
4
5
|
interface ModuleOptions {
|
|
5
6
|
/**
|
|
@@ -42,21 +43,23 @@ interface ModuleOptions {
|
|
|
42
43
|
*/
|
|
43
44
|
clientOptions?: Partial<PostHogConfig>;
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* PostHog Server options
|
|
47
|
+
* @default {
|
|
48
|
+
* api_host: process.env.POSTHOG_API_HOST,
|
|
49
|
+
* }
|
|
50
|
+
* @type object
|
|
51
|
+
* @docs https://posthog.com/docs/libraries/node#config
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
serverOptions?: Partial<PostHogOptions>;
|
|
51
54
|
/**
|
|
52
55
|
* If set to true, the module will be enabled on the client side.
|
|
53
|
-
* @default
|
|
56
|
+
* @default false
|
|
54
57
|
* @type boolean
|
|
55
58
|
*/
|
|
56
59
|
client?: boolean;
|
|
57
60
|
/**
|
|
58
61
|
* If set to true, the module will be enabled on the server side.
|
|
59
|
-
* @default
|
|
62
|
+
* @default false
|
|
60
63
|
* @type boolean
|
|
61
64
|
*/
|
|
62
65
|
server?: boolean;
|
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({
|
|
@@ -11,35 +11,35 @@ const module$1 = defineNuxtModule({
|
|
|
11
11
|
host: process.env.POSTHOG_API_HOST,
|
|
12
12
|
capturePageViews: true,
|
|
13
13
|
capturePageLeaves: true,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
server: true,
|
|
14
|
+
client: false,
|
|
15
|
+
server: false,
|
|
17
16
|
proxy: false
|
|
18
17
|
},
|
|
19
18
|
setup(options, nuxt) {
|
|
20
19
|
const { resolve } = createResolver(import.meta.url);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
const mergedKeyHost = defu(nuxt.options.runtimeConfig.public.posthog, { key: options.key, host: options.host });
|
|
21
|
+
if (options.server) {
|
|
22
|
+
nuxt.options.runtimeConfig.posthog = {
|
|
23
|
+
...nuxt.options.runtimeConfig.posthog,
|
|
24
|
+
server: true,
|
|
25
|
+
...options.serverOptions && { serverOptions: options.serverOptions }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (options.client) {
|
|
29
|
+
nuxt.options.runtimeConfig.public.posthog = {
|
|
30
|
+
...nuxt.options.runtimeConfig.public.posthog,
|
|
31
|
+
key: mergedKeyHost.key,
|
|
32
|
+
host: mergedKeyHost.host,
|
|
33
|
+
capturePageViews: options.capturePageViews,
|
|
34
|
+
capturePageLeaves: options.capturePageLeaves,
|
|
35
|
+
clientOptions: options.clientOptions,
|
|
36
|
+
proxy: options.proxy,
|
|
37
|
+
client: true
|
|
38
|
+
};
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
const url = new URL(
|
|
40
|
+
const publicPosthog = nuxt.options.runtimeConfig.public.posthog;
|
|
41
|
+
if (publicPosthog?.proxy && publicPosthog?.host) {
|
|
42
|
+
const url = new URL(publicPosthog.host);
|
|
43
43
|
const region = url.hostname.split(".")[0];
|
|
44
44
|
if (!region) {
|
|
45
45
|
throw new Error("Invalid PostHog API host when setting proxy");
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import type { PostHog } from 'posthog-js';
|
|
2
|
-
declare const _default: import("
|
|
2
|
+
declare const _default: import("#app").Plugin<{
|
|
3
3
|
posthog: "Deprecated: use $clientPosthog instead.";
|
|
4
4
|
clientPosthog: PostHog | null;
|
|
5
|
-
}> & import("
|
|
5
|
+
}> & import("#app").ObjectPlugin<{
|
|
6
6
|
posthog: "Deprecated: use $clientPosthog instead.";
|
|
7
7
|
clientPosthog: PostHog | null;
|
|
8
8
|
}>;
|
|
@@ -1,19 +1,22 @@
|
|
|
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
|
-
enforce: "
|
|
6
|
-
setup: async () => {
|
|
7
|
-
console.log("setup posthog client");
|
|
8
|
-
const runtimeConfig = useRuntimeConfig().posthog;
|
|
5
|
+
enforce: "post",
|
|
6
|
+
setup: async (nuxtApp) => {
|
|
9
7
|
const config = useRuntimeConfig().public.posthog;
|
|
10
|
-
if (!config
|
|
8
|
+
if (!config?.client)
|
|
11
9
|
return {
|
|
12
10
|
provide: {
|
|
13
11
|
posthog: "Deprecated: use $clientPosthog instead.",
|
|
14
12
|
clientPosthog: null
|
|
15
13
|
}
|
|
16
14
|
};
|
|
15
|
+
if (!config.key || !config.host) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"PostHog client is enabled but key or host not found. Set client to false in module options to disable."
|
|
18
|
+
);
|
|
19
|
+
}
|
|
17
20
|
const posthog = (await import("posthog-js")).posthog;
|
|
18
21
|
const posthogFeatureFlags = useState("ph-feature-flags");
|
|
19
22
|
const posthogFeatureFlagPayloads = useState("ph-feature-flag-payloads");
|
|
@@ -33,8 +36,7 @@ export default defineNuxtPlugin({
|
|
|
33
36
|
clientOptions.api_host = `${window.location.origin}/ingest/ph`;
|
|
34
37
|
}
|
|
35
38
|
const posthogClient = posthog.init(config.key, clientOptions);
|
|
36
|
-
|
|
37
|
-
identity.value = posthog.get_distinct_id();
|
|
39
|
+
nuxtApp.callHook("posthog:init", posthogClient);
|
|
38
40
|
if (config.capturePageViews) {
|
|
39
41
|
const router = useRouter();
|
|
40
42
|
router.afterEach((to) => {
|
|
@@ -1,13 +1,29 @@
|
|
|
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' {
|
|
6
|
+
/** Server-only config (private). Key/host live in public only; Nitro usePostHog reads serverOptions here. */
|
|
4
7
|
interface RuntimeConfig {
|
|
5
|
-
posthog:
|
|
8
|
+
posthog: {
|
|
9
|
+
server: boolean;
|
|
10
|
+
serverOptions?: ModuleOptions['serverOptions'];
|
|
11
|
+
};
|
|
6
12
|
}
|
|
13
|
+
/** Client config (public). Single source of truth for key/host. Read in client plugins and server plugin. */
|
|
7
14
|
interface PublicRuntimeConfig {
|
|
8
15
|
posthog?: Pick<
|
|
9
16
|
ModuleOptions,
|
|
10
17
|
'key' | 'host' | 'capturePageViews' | 'capturePageLeaves' | 'clientOptions' | 'proxy'
|
|
11
|
-
|
|
18
|
+
> & {
|
|
19
|
+
client: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
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;
|
|
12
28
|
}
|
|
13
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PostHog } from 'posthog-node';
|
|
2
|
-
export declare const usePostHog: () => Promise<PostHog |
|
|
2
|
+
export declare const usePostHog: () => Promise<PostHog | null>;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
const POSTHOG_SERVER_MISSING = "PostHog server is enabled but key or host not found. Set server to false in module options to disable.";
|
|
2
3
|
let posthog = null;
|
|
3
4
|
export const usePostHog = async () => {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
5
|
+
const serverConfig = useRuntimeConfig().posthog;
|
|
6
|
+
const publicConfig = useRuntimeConfig().public.posthog;
|
|
7
|
+
if (!serverConfig?.server) return null;
|
|
8
|
+
if (!publicConfig?.key || !publicConfig?.host) {
|
|
9
|
+
throw new Error(POSTHOG_SERVER_MISSING);
|
|
10
|
+
}
|
|
7
11
|
if (!posthog) {
|
|
8
12
|
const PostHog = (await import("posthog-node")).PostHog;
|
|
9
|
-
posthog = new PostHog(
|
|
13
|
+
posthog = new PostHog(publicConfig.key, {
|
|
14
|
+
host: publicConfig.host,
|
|
15
|
+
...serverConfig.serverOptions
|
|
16
|
+
});
|
|
10
17
|
}
|
|
11
18
|
return posthog;
|
|
12
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unproducts/nuxt-posthog",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "PostHog module for nuxt",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"posthog-js": "^1.252.0",
|
|
42
|
-
"posthog-node": "5.14.0"
|
|
42
|
+
"posthog-node": "^5.14.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@nuxt/devtools": "^3.1.1",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@nuxt/schema": "^4.2.1",
|
|
49
49
|
"@nuxt/test-utils": "^3.19.1",
|
|
50
50
|
"@types/node": "^24.0.1",
|
|
51
|
+
"baseline-browser-mapping": "^2.9.19",
|
|
51
52
|
"changelogen": "^0.6.1",
|
|
52
53
|
"eslint": "^9.29.0",
|
|
53
54
|
"eslint-config-prettier": "^10.1.5",
|
|
@@ -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,12 +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
|
-
const runtimeConfig = useRuntimeConfig().posthog;
|
|
8
|
-
if (!config || !runtimeConfig.server) return;
|
|
9
|
-
const distinctId = getCookie(event, "ph-identify");
|
|
10
|
-
event.context.posthogId = distinctId;
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useCookie, useRuntimeConfig, useState } from "#app";
|
|
2
|
-
export default defineNuxtPlugin({
|
|
3
|
-
name: "posthog-server",
|
|
4
|
-
enforce: "pre",
|
|
5
|
-
setup: async () => {
|
|
6
|
-
const config = useRuntimeConfig().public.posthog;
|
|
7
|
-
const runtimeConfig = useRuntimeConfig().posthog;
|
|
8
|
-
if (!config || !runtimeConfig.server)
|
|
9
|
-
return {
|
|
10
|
-
provide: {
|
|
11
|
-
serverPosthog: null
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const PostHog = (await import("posthog-node")).PostHog;
|
|
15
|
-
const posthog = new PostHog(config.key, { host: config.host });
|
|
16
|
-
await posthog.reloadFeatureFlags();
|
|
17
|
-
const identity = useCookie("ph-identify", { default: () => "" });
|
|
18
|
-
const { featureFlags, featureFlagPayloads } = await posthog.getAllFlagsAndPayloads(identity.value);
|
|
19
|
-
useState("ph-feature-flags", () => featureFlags);
|
|
20
|
-
useState("ph-feature-flag-payloads", () => featureFlagPayloads);
|
|
21
|
-
return {
|
|
22
|
-
provide: {
|
|
23
|
-
serverPosthog: posthog
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
});
|
|
@@ -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 {};
|