@healthya-team/pharmacy-analytics 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +243 -2
- package/dist/client/index.d.mts +216 -0
- package/dist/client/index.d.ts +216 -0
- package/dist/client/index.js +219 -0
- package/dist/client/index.mjs +163 -0
- package/dist/index.d.mts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +18 -0
- package/dist/index.mjs +0 -0
- package/dist/server/index.d.mts +23 -0
- package/dist/server/index.d.ts +23 -0
- package/dist/server/index.js +1040 -0
- package/dist/server/index.mjs +1012 -0
- package/dist/studio/index.d.mts +395 -0
- package/dist/studio/index.d.ts +395 -0
- package/dist/studio/index.js +8384 -0
- package/dist/studio/index.mjs +8378 -0
- package/package.json +103 -4
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
gtag: (...args: unknown[]) => void;
|
|
7
|
+
dataLayer: unknown[];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Fires an analytics event to GA4 (via gtag) and Mixpanel in parallel.
|
|
12
|
+
* No-ops server-side. GA4 is skipped when gtag is unavailable (e.g. consent denied).
|
|
13
|
+
*/
|
|
14
|
+
declare function trackEvent(eventName: string, params?: Record<string, unknown>): void;
|
|
15
|
+
declare function trackPageView(pagePath: string, pageTitle: string): void;
|
|
16
|
+
interface ConditionTrackingParams {
|
|
17
|
+
condition_slug: string;
|
|
18
|
+
condition_name: string;
|
|
19
|
+
condition_id: string | number;
|
|
20
|
+
branch_corporate_id?: string | number;
|
|
21
|
+
source?: string;
|
|
22
|
+
is_pre_consult: boolean;
|
|
23
|
+
is_private_medication: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function trackConditionViewed(params: ConditionTrackingParams): void;
|
|
26
|
+
interface StartAssessmentClickedParams {
|
|
27
|
+
eligibility_status: 'passed' | 'failed';
|
|
28
|
+
is_nhs: boolean;
|
|
29
|
+
gender: string;
|
|
30
|
+
date_of_birth: string;
|
|
31
|
+
condition_id: string | number;
|
|
32
|
+
condition_name: string;
|
|
33
|
+
branch_corporate_id?: string | number;
|
|
34
|
+
}
|
|
35
|
+
declare function trackStartAssessmentClicked(params: StartAssessmentClickedParams): void;
|
|
36
|
+
interface EligibilityCheckedParams {
|
|
37
|
+
status: 'passed' | 'failed';
|
|
38
|
+
gender: string;
|
|
39
|
+
date_of_birth: string;
|
|
40
|
+
condition_name: string;
|
|
41
|
+
condition_id: string | number;
|
|
42
|
+
branch_corporate_id?: string | number;
|
|
43
|
+
}
|
|
44
|
+
declare function trackEligibilityChecked(params: EligibilityCheckedParams): void;
|
|
45
|
+
interface QuestionnaireFlowStepParams {
|
|
46
|
+
step: string;
|
|
47
|
+
condition_token: string;
|
|
48
|
+
condition_id: string | number;
|
|
49
|
+
condition_name: string;
|
|
50
|
+
user_journey_flow: string;
|
|
51
|
+
branch_corporate_id?: string | number;
|
|
52
|
+
}
|
|
53
|
+
declare function trackQuestionnaireFlowStep(params: QuestionnaireFlowStepParams): void;
|
|
54
|
+
interface ProductTrackingParams {
|
|
55
|
+
product_slug: string;
|
|
56
|
+
product_name: string;
|
|
57
|
+
product_id: string | number;
|
|
58
|
+
core_drug_id?: number;
|
|
59
|
+
branch_corporate_id?: string | number;
|
|
60
|
+
condition_id?: string | number;
|
|
61
|
+
condition_name?: string;
|
|
62
|
+
source?: string;
|
|
63
|
+
category_type?: string;
|
|
64
|
+
}
|
|
65
|
+
declare function trackProductViewed(params: ProductTrackingParams): void;
|
|
66
|
+
interface GetTreatmentClickedParams {
|
|
67
|
+
product_slug: string;
|
|
68
|
+
product_name: string;
|
|
69
|
+
category_type?: string;
|
|
70
|
+
product_id: string | number;
|
|
71
|
+
core_drug_id?: number;
|
|
72
|
+
branch_corporate_id?: string | number;
|
|
73
|
+
condition_id?: string | number;
|
|
74
|
+
condition_name?: string;
|
|
75
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
76
|
+
button_origin?: string;
|
|
77
|
+
}
|
|
78
|
+
declare function trackGetTreatmentClicked(params: GetTreatmentClickedParams): void;
|
|
79
|
+
interface PMStartAssessmentClickedParams {
|
|
80
|
+
branch_corporate_id?: string | number;
|
|
81
|
+
condition_id?: string | number;
|
|
82
|
+
condition_name?: string;
|
|
83
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
84
|
+
}
|
|
85
|
+
declare function trackPMStartAssessmentClicked(params: PMStartAssessmentClickedParams): void;
|
|
86
|
+
interface AuthCompletedParams {
|
|
87
|
+
method: 'signup' | 'signin' | 'guest' | 'already_logged_in';
|
|
88
|
+
branch_corporate_id?: string | number;
|
|
89
|
+
core_drug_id?: number;
|
|
90
|
+
condition_id?: string | number;
|
|
91
|
+
condition_name?: string;
|
|
92
|
+
formulary?: string;
|
|
93
|
+
product_name?: string;
|
|
94
|
+
user_name?: string;
|
|
95
|
+
user_email?: string;
|
|
96
|
+
user_gender?: string;
|
|
97
|
+
user_phone?: string;
|
|
98
|
+
user_dob?: string;
|
|
99
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
100
|
+
}
|
|
101
|
+
declare function trackAuthCompleted(params: AuthCompletedParams): void;
|
|
102
|
+
interface QuestionnairePmParams {
|
|
103
|
+
product_id?: string | number;
|
|
104
|
+
product_slug?: string;
|
|
105
|
+
product_name?: string;
|
|
106
|
+
core_drug_id?: number;
|
|
107
|
+
condition_id?: string | number;
|
|
108
|
+
condition_name?: string;
|
|
109
|
+
branch_corporate_id?: string | number;
|
|
110
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
111
|
+
}
|
|
112
|
+
declare function trackQuestionnairePm(params: QuestionnairePmParams): void;
|
|
113
|
+
interface CartViewedParams {
|
|
114
|
+
product_id?: string | number;
|
|
115
|
+
product_slug?: string;
|
|
116
|
+
product_name?: string;
|
|
117
|
+
branch_corporate_id?: string | number;
|
|
118
|
+
core_drug_id?: number;
|
|
119
|
+
condition_id?: string | number;
|
|
120
|
+
condition_name?: string;
|
|
121
|
+
cart_item_count?: number;
|
|
122
|
+
cart_total_price?: number;
|
|
123
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
124
|
+
/** 'signed_in' when user is authenticated, 'guest' when browsing as a guest */
|
|
125
|
+
cart_auth_status?: 'signed_in' | 'guest';
|
|
126
|
+
}
|
|
127
|
+
declare function trackCartViewed(params: CartViewedParams): void;
|
|
128
|
+
interface CheckoutStartedParams {
|
|
129
|
+
product_id?: string | number;
|
|
130
|
+
product_slug?: string;
|
|
131
|
+
product_name?: string;
|
|
132
|
+
branch_corporate_id?: string | number;
|
|
133
|
+
core_drug_id?: number;
|
|
134
|
+
condition_id?: string | number;
|
|
135
|
+
condition_name?: string;
|
|
136
|
+
cart_item_count?: number;
|
|
137
|
+
cart_total_price?: number;
|
|
138
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
139
|
+
}
|
|
140
|
+
declare function trackCheckoutStarted(params: CheckoutStartedParams): void;
|
|
141
|
+
interface OrderSuccessParams {
|
|
142
|
+
product_id?: string | number;
|
|
143
|
+
product_slug?: string;
|
|
144
|
+
product_name?: string;
|
|
145
|
+
branch_corporate_id?: string | number;
|
|
146
|
+
core_drug_id?: number;
|
|
147
|
+
condition_id?: string | number;
|
|
148
|
+
condition_name?: string;
|
|
149
|
+
order_id?: string | number;
|
|
150
|
+
cart_item_count?: number;
|
|
151
|
+
cart_total_price?: number;
|
|
152
|
+
payment_mode?: string;
|
|
153
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
154
|
+
}
|
|
155
|
+
declare function trackOrderSuccess(params: OrderSuccessParams): void;
|
|
156
|
+
interface CartAuthCompletedParams {
|
|
157
|
+
method: 'signup' | 'signin' | 'guest';
|
|
158
|
+
product_id?: string | number;
|
|
159
|
+
product_slug?: string;
|
|
160
|
+
product_name?: string;
|
|
161
|
+
branch_corporate_id?: string | number;
|
|
162
|
+
core_drug_id?: number;
|
|
163
|
+
condition_id?: string | number;
|
|
164
|
+
condition_name?: string;
|
|
165
|
+
user_name?: string;
|
|
166
|
+
user_email?: string;
|
|
167
|
+
user_gender?: string;
|
|
168
|
+
user_phone?: string;
|
|
169
|
+
user_dob?: string;
|
|
170
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
171
|
+
}
|
|
172
|
+
declare function trackCartAuthCompleted(params: CartAuthCompletedParams): void;
|
|
173
|
+
interface ProductSelectedParams {
|
|
174
|
+
product_id?: string | number;
|
|
175
|
+
product_slug?: string;
|
|
176
|
+
product_name?: string;
|
|
177
|
+
core_drug_id?: number;
|
|
178
|
+
condition_id?: string | number;
|
|
179
|
+
condition_name?: string;
|
|
180
|
+
branch_corporate_id?: string | number;
|
|
181
|
+
pm_flow_source?: 'product_detail' | 'condition_detail';
|
|
182
|
+
}
|
|
183
|
+
declare function trackProductSelected(params: ProductSelectedParams): void;
|
|
184
|
+
interface ConditionSearchedParams {
|
|
185
|
+
search_term: string;
|
|
186
|
+
results_count: number;
|
|
187
|
+
source: 'hero' | 'nav' | 'mobile_nav' | 'page';
|
|
188
|
+
}
|
|
189
|
+
declare function trackConditionSearched(params: ConditionSearchedParams): void;
|
|
190
|
+
interface ProductSearchedParams {
|
|
191
|
+
search_term: string;
|
|
192
|
+
results_count: number;
|
|
193
|
+
}
|
|
194
|
+
declare function trackProductSearched(params: ProductSearchedParams): void;
|
|
195
|
+
|
|
196
|
+
interface GaScriptProps {
|
|
197
|
+
measurementId?: string | null;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Injects the GA4 gtag.js script globally in Next.js layout.
|
|
201
|
+
*
|
|
202
|
+
* Loaded with `beforeInteractive` priority so `gtag` is always available.
|
|
203
|
+
* Consent is initialized as DENIED by default until user accepts cookies.
|
|
204
|
+
*/
|
|
205
|
+
declare function GaScript({ measurementId }: GaScriptProps): react_jsx_runtime.JSX.Element | null;
|
|
206
|
+
|
|
207
|
+
interface MixpanelInitProps {
|
|
208
|
+
token?: string | null;
|
|
209
|
+
}
|
|
210
|
+
declare function MixpanelInit({ token }?: MixpanelInitProps): null;
|
|
211
|
+
|
|
212
|
+
declare function AnalyticsProvider({ children }: {
|
|
213
|
+
children: React.ReactNode;
|
|
214
|
+
}): react_jsx_runtime.JSX.Element;
|
|
215
|
+
|
|
216
|
+
export { AnalyticsProvider, type AuthCompletedParams, type CartAuthCompletedParams, type CartViewedParams, type CheckoutStartedParams, type ConditionSearchedParams, type ConditionTrackingParams, type EligibilityCheckedParams, GaScript, type GaScriptProps, type GetTreatmentClickedParams, MixpanelInit, type MixpanelInitProps, type OrderSuccessParams, type PMStartAssessmentClickedParams, type ProductSearchedParams, type ProductSelectedParams, type ProductTrackingParams, type QuestionnaireFlowStepParams, type QuestionnairePmParams, type StartAssessmentClickedParams, trackAuthCompleted, trackCartAuthCompleted, trackCartViewed, trackCheckoutStarted, trackConditionSearched, trackConditionViewed, trackEligibilityChecked, trackEvent, trackGetTreatmentClicked, trackOrderSuccess, trackPMStartAssessmentClicked, trackPageView, trackProductSearched, trackProductSelected, trackProductViewed, trackQuestionnaireFlowStep, trackQuestionnairePm, trackStartAssessmentClicked };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/client/index.ts
|
|
32
|
+
var client_exports = {};
|
|
33
|
+
__export(client_exports, {
|
|
34
|
+
AnalyticsProvider: () => AnalyticsProvider,
|
|
35
|
+
GaScript: () => GaScript,
|
|
36
|
+
MixpanelInit: () => MixpanelInit,
|
|
37
|
+
trackAuthCompleted: () => trackAuthCompleted,
|
|
38
|
+
trackCartAuthCompleted: () => trackCartAuthCompleted,
|
|
39
|
+
trackCartViewed: () => trackCartViewed,
|
|
40
|
+
trackCheckoutStarted: () => trackCheckoutStarted,
|
|
41
|
+
trackConditionSearched: () => trackConditionSearched,
|
|
42
|
+
trackConditionViewed: () => trackConditionViewed,
|
|
43
|
+
trackEligibilityChecked: () => trackEligibilityChecked,
|
|
44
|
+
trackEvent: () => trackEvent,
|
|
45
|
+
trackGetTreatmentClicked: () => trackGetTreatmentClicked,
|
|
46
|
+
trackOrderSuccess: () => trackOrderSuccess,
|
|
47
|
+
trackPMStartAssessmentClicked: () => trackPMStartAssessmentClicked,
|
|
48
|
+
trackPageView: () => trackPageView,
|
|
49
|
+
trackProductSearched: () => trackProductSearched,
|
|
50
|
+
trackProductSelected: () => trackProductSelected,
|
|
51
|
+
trackProductViewed: () => trackProductViewed,
|
|
52
|
+
trackQuestionnaireFlowStep: () => trackQuestionnaireFlowStep,
|
|
53
|
+
trackQuestionnairePm: () => trackQuestionnairePm,
|
|
54
|
+
trackStartAssessmentClicked: () => trackStartAssessmentClicked
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(client_exports);
|
|
57
|
+
|
|
58
|
+
// src/client/analytics.ts
|
|
59
|
+
var import_mixpanel_browser = __toESM(require("mixpanel-browser"));
|
|
60
|
+
function trackEvent(eventName, params) {
|
|
61
|
+
if (typeof window === "undefined") {
|
|
62
|
+
console.log(`\u{1F4CA} trackEvent("${eventName}") called but window is undefined`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (typeof window.gtag !== "function") {
|
|
66
|
+
console.warn(`\u26A0\uFE0F trackEvent("${eventName}") called but gtag is not available. Consent might be denied.`);
|
|
67
|
+
} else {
|
|
68
|
+
console.log(`\u2705 Firing GA4 event: "${eventName}"`, params);
|
|
69
|
+
window.gtag("event", eventName, params);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
import_mixpanel_browser.default.track(eventName, params);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.warn(`\u26A0\uFE0F Mixpanel track failed for "${eventName}":`, err);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function trackPageView(pagePath, pageTitle) {
|
|
78
|
+
trackEvent("page_view", { page_path: pagePath, page_title: pageTitle });
|
|
79
|
+
}
|
|
80
|
+
function trackConditionViewed(params) {
|
|
81
|
+
trackEvent("condition_viewed", params);
|
|
82
|
+
}
|
|
83
|
+
function trackStartAssessmentClicked(params) {
|
|
84
|
+
trackEvent("start_assessment_clicked", params);
|
|
85
|
+
}
|
|
86
|
+
function trackEligibilityChecked(params) {
|
|
87
|
+
trackEvent("eligibility_checked", params);
|
|
88
|
+
}
|
|
89
|
+
function trackQuestionnaireFlowStep(params) {
|
|
90
|
+
trackEvent("questionnaire_flow_step", params);
|
|
91
|
+
}
|
|
92
|
+
function trackProductViewed(params) {
|
|
93
|
+
trackEvent("product_viewed", params);
|
|
94
|
+
}
|
|
95
|
+
function trackGetTreatmentClicked(params) {
|
|
96
|
+
trackEvent("get_treatment_clicked", params);
|
|
97
|
+
}
|
|
98
|
+
function trackPMStartAssessmentClicked(params) {
|
|
99
|
+
trackEvent("pm_start_assessment_clicked", params);
|
|
100
|
+
}
|
|
101
|
+
function trackAuthCompleted(params) {
|
|
102
|
+
trackEvent("auth_completed", params);
|
|
103
|
+
}
|
|
104
|
+
function trackQuestionnairePm(params) {
|
|
105
|
+
trackEvent("questionnaire_pm", params);
|
|
106
|
+
}
|
|
107
|
+
function trackCartViewed(params) {
|
|
108
|
+
trackEvent("cart_viewed", params);
|
|
109
|
+
}
|
|
110
|
+
function trackCheckoutStarted(params) {
|
|
111
|
+
trackEvent("checkout_started", params);
|
|
112
|
+
}
|
|
113
|
+
function trackOrderSuccess(params) {
|
|
114
|
+
trackEvent("order_success", params);
|
|
115
|
+
}
|
|
116
|
+
function trackCartAuthCompleted(params) {
|
|
117
|
+
trackEvent("cart_auth_completed", params);
|
|
118
|
+
}
|
|
119
|
+
function trackProductSelected(params) {
|
|
120
|
+
trackEvent("product_selected", params);
|
|
121
|
+
}
|
|
122
|
+
function trackConditionSearched(params) {
|
|
123
|
+
trackEvent("condition_searched", params);
|
|
124
|
+
}
|
|
125
|
+
function trackProductSearched(params) {
|
|
126
|
+
trackEvent("product_searched", params);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/client/GaScript.tsx
|
|
130
|
+
var import_script = __toESM(require("next/script"));
|
|
131
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
132
|
+
function GaScript({ measurementId }) {
|
|
133
|
+
const id = measurementId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID : void 0);
|
|
134
|
+
if (!id) return null;
|
|
135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
136
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
137
|
+
import_script.default,
|
|
138
|
+
{
|
|
139
|
+
id: "ga4-script",
|
|
140
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${id}`,
|
|
141
|
+
strategy: "beforeInteractive"
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_script.default, { id: "ga4-init", strategy: "afterInteractive", children: `
|
|
145
|
+
window.dataLayer = window.dataLayer || [];
|
|
146
|
+
function gtag(){dataLayer.push(arguments);}
|
|
147
|
+
gtag('js', new Date());
|
|
148
|
+
|
|
149
|
+
// Default consent state \u2014 denied until user accepts cookies
|
|
150
|
+
gtag('consent', 'default', {
|
|
151
|
+
analytics_storage: 'denied',
|
|
152
|
+
ad_storage: 'denied',
|
|
153
|
+
wait_for_update: 500
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
gtag('config', '${id}', {
|
|
157
|
+
send_page_view: false,
|
|
158
|
+
});
|
|
159
|
+
` })
|
|
160
|
+
] });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/client/MixpanelInit.tsx
|
|
164
|
+
var import_react = require("react");
|
|
165
|
+
var import_mixpanel_browser2 = __toESM(require("mixpanel-browser"));
|
|
166
|
+
function MixpanelInit({ token } = {}) {
|
|
167
|
+
(0, import_react.useEffect)(() => {
|
|
168
|
+
const activeToken = token || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_MIX_PANEL_TOKEN : void 0);
|
|
169
|
+
if (!activeToken) return;
|
|
170
|
+
import_mixpanel_browser2.default.init(activeToken, {
|
|
171
|
+
persistence: "localStorage",
|
|
172
|
+
autocapture: false,
|
|
173
|
+
track_pageview: false,
|
|
174
|
+
record_sessions_percent: 0
|
|
175
|
+
});
|
|
176
|
+
}, [token]);
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/client/AnalyticsProvider.tsx
|
|
181
|
+
var import_react2 = require("react");
|
|
182
|
+
var import_navigation = require("next/navigation");
|
|
183
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
184
|
+
function AnalyticsProvider({ children }) {
|
|
185
|
+
const pathname = (0, import_navigation.usePathname)();
|
|
186
|
+
(0, import_react2.useEffect)(() => {
|
|
187
|
+
if (typeof window === "undefined") return;
|
|
188
|
+
if (window.__lastTrackedPath === pathname) return;
|
|
189
|
+
window.__lastTrackedPath = pathname;
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
trackPageView(pathname, typeof document !== "undefined" ? document.title : "");
|
|
192
|
+
}, 0);
|
|
193
|
+
}, [pathname]);
|
|
194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
|
|
195
|
+
}
|
|
196
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
197
|
+
0 && (module.exports = {
|
|
198
|
+
AnalyticsProvider,
|
|
199
|
+
GaScript,
|
|
200
|
+
MixpanelInit,
|
|
201
|
+
trackAuthCompleted,
|
|
202
|
+
trackCartAuthCompleted,
|
|
203
|
+
trackCartViewed,
|
|
204
|
+
trackCheckoutStarted,
|
|
205
|
+
trackConditionSearched,
|
|
206
|
+
trackConditionViewed,
|
|
207
|
+
trackEligibilityChecked,
|
|
208
|
+
trackEvent,
|
|
209
|
+
trackGetTreatmentClicked,
|
|
210
|
+
trackOrderSuccess,
|
|
211
|
+
trackPMStartAssessmentClicked,
|
|
212
|
+
trackPageView,
|
|
213
|
+
trackProductSearched,
|
|
214
|
+
trackProductSelected,
|
|
215
|
+
trackProductViewed,
|
|
216
|
+
trackQuestionnaireFlowStep,
|
|
217
|
+
trackQuestionnairePm,
|
|
218
|
+
trackStartAssessmentClicked
|
|
219
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/client/analytics.ts
|
|
4
|
+
import mixpanel from "mixpanel-browser";
|
|
5
|
+
function trackEvent(eventName, params) {
|
|
6
|
+
if (typeof window === "undefined") {
|
|
7
|
+
console.log(`\u{1F4CA} trackEvent("${eventName}") called but window is undefined`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (typeof window.gtag !== "function") {
|
|
11
|
+
console.warn(`\u26A0\uFE0F trackEvent("${eventName}") called but gtag is not available. Consent might be denied.`);
|
|
12
|
+
} else {
|
|
13
|
+
console.log(`\u2705 Firing GA4 event: "${eventName}"`, params);
|
|
14
|
+
window.gtag("event", eventName, params);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
mixpanel.track(eventName, params);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.warn(`\u26A0\uFE0F Mixpanel track failed for "${eventName}":`, err);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function trackPageView(pagePath, pageTitle) {
|
|
23
|
+
trackEvent("page_view", { page_path: pagePath, page_title: pageTitle });
|
|
24
|
+
}
|
|
25
|
+
function trackConditionViewed(params) {
|
|
26
|
+
trackEvent("condition_viewed", params);
|
|
27
|
+
}
|
|
28
|
+
function trackStartAssessmentClicked(params) {
|
|
29
|
+
trackEvent("start_assessment_clicked", params);
|
|
30
|
+
}
|
|
31
|
+
function trackEligibilityChecked(params) {
|
|
32
|
+
trackEvent("eligibility_checked", params);
|
|
33
|
+
}
|
|
34
|
+
function trackQuestionnaireFlowStep(params) {
|
|
35
|
+
trackEvent("questionnaire_flow_step", params);
|
|
36
|
+
}
|
|
37
|
+
function trackProductViewed(params) {
|
|
38
|
+
trackEvent("product_viewed", params);
|
|
39
|
+
}
|
|
40
|
+
function trackGetTreatmentClicked(params) {
|
|
41
|
+
trackEvent("get_treatment_clicked", params);
|
|
42
|
+
}
|
|
43
|
+
function trackPMStartAssessmentClicked(params) {
|
|
44
|
+
trackEvent("pm_start_assessment_clicked", params);
|
|
45
|
+
}
|
|
46
|
+
function trackAuthCompleted(params) {
|
|
47
|
+
trackEvent("auth_completed", params);
|
|
48
|
+
}
|
|
49
|
+
function trackQuestionnairePm(params) {
|
|
50
|
+
trackEvent("questionnaire_pm", params);
|
|
51
|
+
}
|
|
52
|
+
function trackCartViewed(params) {
|
|
53
|
+
trackEvent("cart_viewed", params);
|
|
54
|
+
}
|
|
55
|
+
function trackCheckoutStarted(params) {
|
|
56
|
+
trackEvent("checkout_started", params);
|
|
57
|
+
}
|
|
58
|
+
function trackOrderSuccess(params) {
|
|
59
|
+
trackEvent("order_success", params);
|
|
60
|
+
}
|
|
61
|
+
function trackCartAuthCompleted(params) {
|
|
62
|
+
trackEvent("cart_auth_completed", params);
|
|
63
|
+
}
|
|
64
|
+
function trackProductSelected(params) {
|
|
65
|
+
trackEvent("product_selected", params);
|
|
66
|
+
}
|
|
67
|
+
function trackConditionSearched(params) {
|
|
68
|
+
trackEvent("condition_searched", params);
|
|
69
|
+
}
|
|
70
|
+
function trackProductSearched(params) {
|
|
71
|
+
trackEvent("product_searched", params);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/client/GaScript.tsx
|
|
75
|
+
import Script from "next/script";
|
|
76
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
77
|
+
function GaScript({ measurementId }) {
|
|
78
|
+
const id = measurementId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID : void 0);
|
|
79
|
+
if (!id) return null;
|
|
80
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
+
/* @__PURE__ */ jsx(
|
|
82
|
+
Script,
|
|
83
|
+
{
|
|
84
|
+
id: "ga4-script",
|
|
85
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${id}`,
|
|
86
|
+
strategy: "beforeInteractive"
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
/* @__PURE__ */ jsx(Script, { id: "ga4-init", strategy: "afterInteractive", children: `
|
|
90
|
+
window.dataLayer = window.dataLayer || [];
|
|
91
|
+
function gtag(){dataLayer.push(arguments);}
|
|
92
|
+
gtag('js', new Date());
|
|
93
|
+
|
|
94
|
+
// Default consent state \u2014 denied until user accepts cookies
|
|
95
|
+
gtag('consent', 'default', {
|
|
96
|
+
analytics_storage: 'denied',
|
|
97
|
+
ad_storage: 'denied',
|
|
98
|
+
wait_for_update: 500
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
gtag('config', '${id}', {
|
|
102
|
+
send_page_view: false,
|
|
103
|
+
});
|
|
104
|
+
` })
|
|
105
|
+
] });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/client/MixpanelInit.tsx
|
|
109
|
+
import { useEffect } from "react";
|
|
110
|
+
import mixpanel2 from "mixpanel-browser";
|
|
111
|
+
function MixpanelInit({ token } = {}) {
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const activeToken = token || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_MIX_PANEL_TOKEN : void 0);
|
|
114
|
+
if (!activeToken) return;
|
|
115
|
+
mixpanel2.init(activeToken, {
|
|
116
|
+
persistence: "localStorage",
|
|
117
|
+
autocapture: false,
|
|
118
|
+
track_pageview: false,
|
|
119
|
+
record_sessions_percent: 0
|
|
120
|
+
});
|
|
121
|
+
}, [token]);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/client/AnalyticsProvider.tsx
|
|
126
|
+
import { useEffect as useEffect2 } from "react";
|
|
127
|
+
import { usePathname } from "next/navigation";
|
|
128
|
+
import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
|
|
129
|
+
function AnalyticsProvider({ children }) {
|
|
130
|
+
const pathname = usePathname();
|
|
131
|
+
useEffect2(() => {
|
|
132
|
+
if (typeof window === "undefined") return;
|
|
133
|
+
if (window.__lastTrackedPath === pathname) return;
|
|
134
|
+
window.__lastTrackedPath = pathname;
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
trackPageView(pathname, typeof document !== "undefined" ? document.title : "");
|
|
137
|
+
}, 0);
|
|
138
|
+
}, [pathname]);
|
|
139
|
+
return /* @__PURE__ */ jsx2(Fragment2, { children });
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
AnalyticsProvider,
|
|
143
|
+
GaScript,
|
|
144
|
+
MixpanelInit,
|
|
145
|
+
trackAuthCompleted,
|
|
146
|
+
trackCartAuthCompleted,
|
|
147
|
+
trackCartViewed,
|
|
148
|
+
trackCheckoutStarted,
|
|
149
|
+
trackConditionSearched,
|
|
150
|
+
trackConditionViewed,
|
|
151
|
+
trackEligibilityChecked,
|
|
152
|
+
trackEvent,
|
|
153
|
+
trackGetTreatmentClicked,
|
|
154
|
+
trackOrderSuccess,
|
|
155
|
+
trackPMStartAssessmentClicked,
|
|
156
|
+
trackPageView,
|
|
157
|
+
trackProductSearched,
|
|
158
|
+
trackProductSelected,
|
|
159
|
+
trackProductViewed,
|
|
160
|
+
trackQuestionnaireFlowStep,
|
|
161
|
+
trackQuestionnairePm,
|
|
162
|
+
trackStartAssessmentClicked
|
|
163
|
+
};
|