Skip to content

Commit c2bf1b8

Browse files
committed
Enable to provide eulerian params when starting
1 parent 793a186 commit c2bf1b8

File tree

5 files changed

+99
-8
lines changed

5 files changed

+99
-8
lines changed

src/next-appdir/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type { RegisterLink } from "../link";
22
export type { DefaultColorScheme } from "./zz_internal/defaultColorScheme";
33
export { startReactDsfr } from "./zz_internal/start";
4+
export type { EulerianAnalytics } from "../start";

src/next-appdir/zz_internal/start.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactNode } from "react";
2-
import { start } from "../../start";
2+
import { start, type EulerianAnalytics } from "../../start";
33
import type { RegisteredLinkProps } from "../../link";
44
import { setLink } from "../../link";
55
import { type DefaultColorScheme, setDefaultColorSchemeClientSide } from "./defaultColorScheme";
@@ -14,8 +14,9 @@ export function startReactDsfr(params: {
1414
verbose?: boolean;
1515
/** Default: <a /> */
1616
Link?: (props: RegisteredLinkProps & { children: ReactNode }) => ReturnType<React.FC>;
17+
eulerianAnalytics?: EulerianAnalytics;
1718
}) {
18-
const { defaultColorScheme, verbose = false, Link } = params;
19+
const { defaultColorScheme, verbose = false, Link, eulerianAnalytics } = params;
1920

2021
setDefaultColorSchemeClientSide({ defaultColorScheme });
2122

@@ -27,6 +28,7 @@ export function startReactDsfr(params: {
2728
start({
2829
defaultColorScheme,
2930
verbose,
31+
eulerianAnalytics,
3032
"nextParams": {
3133
"doPersistDarkModePreferenceWithCookie": false,
3234
"registerEffectAction": action => {

src/next-pagesdir.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import FaviconSvg from "./dsfr/favicon/favicon.svg";
1616
import FaviconIco from "./dsfr/favicon/favicon.ico";
1717
import { getAssetUrl } from "./tools/getAssetUrl";
1818
import { getColors } from "./fr/colors";
19-
import { start } from "./start";
19+
import { start, type EulerianAnalytics } from "./start";
2020
import type { RegisterLink, RegisteredLinkProps } from "./link";
2121
import { setLink } from "./link";
2222
import { setUseLang } from "./i18n";
2323
import { assert } from "tsafe/assert";
2424
import "./assets/dsfr_plus_icons.css";
2525

26+
export type { EulerianAnalytics };
27+
2628
const isProduction = process.env.NODE_ENV !== "development";
2729

2830
export type { RegisterLink, RegisteredLinkProps };
@@ -41,6 +43,7 @@ export type CreateNextDsfrIntegrationApiParams = {
4143
doPersistDarkModePreferenceWithCookie?: boolean;
4244
/** Default: ()=> "fr" */
4345
useLang?: () => string;
46+
eulerianAnalytics?: EulerianAnalytics;
4447
};
4548

4649
function readIsDarkInCookie(cookie: string) {
@@ -88,7 +91,8 @@ export function createNextDsfrIntegrationApi(
8891
Link,
8992
preloadFonts = [],
9093
doPersistDarkModePreferenceWithCookie = false,
91-
useLang
94+
useLang,
95+
eulerianAnalytics
9296
} = params;
9397

9498
let isAfterFirstEffect = false;
@@ -106,6 +110,7 @@ export function createNextDsfrIntegrationApi(
106110
start({
107111
defaultColorScheme,
108112
verbose,
113+
eulerianAnalytics,
109114
"nextParams": {
110115
doPersistDarkModePreferenceWithCookie,
111116
"registerEffectAction": action => {

src/spa.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { ReactNode } from "react";
2-
import { start } from "./start";
2+
import { start, type EulerianAnalytics } from "./start";
33
import type { RegisterLink, RegisteredLinkProps } from "./link";
44
import { setLink } from "./link";
55
import { setUseLang } from "./i18n";
66
import type { ColorScheme } from "./useIsDark";
77

8+
export type { EulerianAnalytics };
9+
810
export type { RegisterLink, RegisteredLinkProps };
911

1012
export function startReactDsfr(params: {
@@ -15,8 +17,9 @@ export function startReactDsfr(params: {
1517
Link?: (props: RegisteredLinkProps & { children: ReactNode }) => ReturnType<React.FC>;
1618
/** Default: ()=> "fr" */
1719
useLang?: () => string;
20+
eulerianAnalytics?: EulerianAnalytics;
1821
}) {
19-
const { defaultColorScheme, verbose = false, Link, useLang } = params;
22+
const { defaultColorScheme, verbose = false, Link, useLang, eulerianAnalytics } = params;
2023

2124
if (Link !== undefined) {
2225
setLink({ Link });
@@ -29,6 +32,7 @@ export function startReactDsfr(params: {
2932
start({
3033
defaultColorScheme,
3134
verbose,
35+
eulerianAnalytics,
3236
"nextParams": undefined
3337
});
3438
}

src/start.ts

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { startClientSideIsDarkLogic } from "./useIsDark/client";
66
type Params = {
77
defaultColorScheme: ColorScheme | "system";
88
verbose: boolean;
9+
eulerianAnalytics: EulerianAnalytics | undefined;
910
nextParams:
1011
| {
1112
doPersistDarkModePreferenceWithCookie: boolean;
@@ -17,7 +18,7 @@ type Params = {
1718
let isStarted = false;
1819

1920
export async function start(params: Params) {
20-
const { defaultColorScheme, verbose, nextParams } = params;
21+
const { defaultColorScheme, verbose, nextParams, eulerianAnalytics } = params;
2122

2223
assert(isBrowser);
2324

@@ -37,11 +38,89 @@ export async function start(params: Params) {
3738
registerEffectAction
3839
});
3940

40-
(window as any).dsfr = { verbose, "mode": "react" };
41+
(window as any).dsfr = {
42+
verbose,
43+
"mode": "react",
44+
"analytics": eulerianAnalytics
45+
};
4146

4247
await import("./dsfr/dsfr.module" as any);
4348

49+
if (eulerianAnalytics !== undefined) {
50+
await import("./dsfr/analytics/analytics.module.js" as any);
51+
}
52+
4453
const { dsfr } = window as unknown as { dsfr: { start: () => void } };
4554

4655
registerEffectAction(() => dsfr.start());
4756
}
57+
58+
export type EulerianAnalytics = {
59+
domain: string;
60+
/** default: false */
61+
enableRating?: boolean;
62+
page?: Partial<{
63+
path: string; // path for page tracking
64+
referrer: string; // referrer for virtual pages (not for real page, eulerian automatically collects document.referrer)
65+
id: string; // unique page id (string)
66+
title: string; // page title for virtual pages
67+
name: string; // equivalent to title if not defined
68+
author: string; // page author name
69+
date: string; // page creation date
70+
labels: string[];
71+
tags: string[]; // no tags limit
72+
template: string; // page template
73+
group: string; // page group. if not defined, fallback to template value
74+
segment: string; // site segment. if not defined, fallback to template value
75+
subtemplate: string; // page subtemplate
76+
theme: string; // page theme
77+
subtheme: string; // page subtheme
78+
related: string; // related page id
79+
depth: number; // page depth
80+
isError: boolean; // is this an error page (404, 500, 503...)
81+
current: number; // In case of pagination, current page number
82+
total: number; // In case of pagination, total pages number
83+
filters: string; // array of filters that were applied on the page (strings)
84+
}>;
85+
site?: Partial<{
86+
environment: "production" | "stage" | "production"; // by default development ['development', 'stage', 'production']
87+
entity: string; // Entity responsible for website
88+
language: string; // language of the website (ISO 639-1). default to html lang
89+
target: string; // site target
90+
type: string; // site type
91+
region: string; // region of the website (ISO 3166-2:FR)
92+
department: string; // department of the website (ISO 3166-2:FR)
93+
}>;
94+
user?: Partial<{
95+
connect: {
96+
uid: string; // user id - required when connected
97+
email: string; // encoded user email - required when connected
98+
isNew: boolean; // user just registered
99+
};
100+
profile: string; // user profile
101+
language: string;
102+
type: string;
103+
}>;
104+
search?: Partial<{
105+
engine: string;
106+
results: number;
107+
terms: string;
108+
category: string;
109+
theme: string;
110+
type: string;
111+
method: string;
112+
}>;
113+
funnel?: Partial<{
114+
id: string;
115+
type: string;
116+
name: string;
117+
step: string; // step name
118+
current: number; // step number
119+
total: number; // total number of steps
120+
objective: string; // form objective
121+
error: string; // form's error type
122+
}>;
123+
cmp?: Partial<{
124+
id: string;
125+
}>;
126+
};

0 commit comments

Comments
 (0)