Commit 65e2d0a
authored
refactor(sdk-analytics): Consolidate analytics data attributes and simplify Contentlet component (#33948)
## Summary
Consolidates analytics data attributes by moving constants from UVE to
sdk-analytics and simplifies the sdk-react `Contentlet` component by
removing redundant analytics state management. Analytics attributes now
always render using UVE's standard contentlet attributes instead of
separate conditional logic.
## Changes Made
### SDK Analytics (`libs/sdk/analytics`)
- **Moved analytics constants** from `@dotcms/uve/internal` to
`sdk-analytics/constants`:
- `ANALYTICS_WINDOWS_ACTIVE_KEY` - Analytics active state flag
- `ANALYTICS_WINDOWS_CLEANUP_KEY` - Analytics cleanup function reference
- `CONTENTLET_CLASS` - Renamed from `ANALYTICS_CONTENTLET_CLASS` to
`dotcms-contentlet`
- **Updated data attribute naming** to use standard UVE attributes:
- `data-dot-analytics-identifier` → `data-dot-identifier`
- `data-dot-analytics-inode` → `data-dot-inode`
- `data-dot-analytics-contenttype` → `data-dot-type`
- `data-dot-analytics-title` → `data-dot-title`
- `data-dot-analytics-basetype` → `data-dot-basetype`
- `data-dot-analytics-dom-index` → `data-dot-dom-index`
- **Updated all analytics plugins** to use consolidated constants and
new attribute names:
-
[dot-analytics.content.ts](core-web/libs/sdk/analytics/src/lib/core/dot-analytics.content.ts)
-
[dot-analytics.identity.activity-tracker.ts](core-web/libs/sdk/analytics/src/lib/core/plugin/identity/dot-analytics.identity.activity-tracker.ts)
-
[dot-analytics.impression-tracker.ts](core-web/libs/sdk/analytics/src/lib/core/plugin/impression/dot-analytics.impression-tracker.ts)
-
[dot-analytics.utils.ts](core-web/libs/sdk/analytics/src/lib/core/shared/utils/dot-analytics.utils.ts)
### SDK React (`libs/sdk/react`)
- **Removed `useIsAnalyticsActive` hook**
([useIsAnalyticsActive.ts](core-web/libs/sdk/react/src/lib/next/hooks/useIsAnalyticsActive.ts))
- No longer needed since analytics attributes always render via UVE
- **Simplified `Contentlet` component**
([Contentlet.tsx:55-78](core-web/libs/sdk/react/src/lib/next/components/Contentlet/Contentlet.tsx#L55-L78)):
- Removed conditional `analyticsAttributes` useMemo
- Removed conditional `containerClassName` useMemo
- Removed `isAnalyticsActive` state check
- Always applies UVE attributes via `getDotContentletAttributes()`
- Always applies `CONTENTLET_CLASS` (`dotcms-contentlet`)
- **Updated tests**
([Contentlet.test.tsx](core-web/libs/sdk/react/src/lib/next/__test__/components/Contentlet.test.tsx)):
- Removed `useIsAnalyticsActive` mock
- Removed `getDotAnalyticsAttributes` mock
- Updated assertions to reflect always-rendered attributes
- Simplified test cases (removed analytics conditional tests)
### SDK UVE (`libs/sdk/uve`)
- **Removed analytics-specific exports** from UVE internal API:
- Removed `getDotAnalyticsAttributes()` function (analytics now uses
standard UVE attributes)
- Removed `isAnalyticsActive()` function (no longer needed)
- Removed `ANALYTICS_WINDOWS_ACTIVE_KEY` and
`ANALYTICS_WINDOWS_CLEANUP_KEY` constants (moved to sdk-analytics)
- Removed 50+ lines of analytics-specific tests
## Technical Details
**Problem**: The sdk-react `Contentlet` component had duplicate
analytics attribute logic that conditionally rendered based on
`isAnalyticsActive && !isDevMode`. This created complexity and separated
analytics attributes from UVE's standard contentlet attributes.
**Solution**:
1. Consolidate analytics constants in `@dotcms/analytics` where they
belong
2. Use UVE's standard `getDotContentletAttributes()` which already
provides all necessary data attributes
3. Remove conditional rendering - analytics attributes always render via
the standard `data-dot-*` attributes
4. Standardize CSS class to `dotcms-contentlet` (used by both UVE and
analytics)
**Benefits**:
- **Simpler component logic** - No analytics state management needed
- **Consistent data attributes** - Single source of truth (UVE)
- **Better separation of concerns** - Analytics constants live in
analytics SDK
- **Always-on tracking** - Analytics attributes always present (no
missed tracking events)
## Breaking Changes
**CSS Class Change**: The analytics contentlet class changed from
`dotcms-analytics-contentlet` to `dotcms-contentlet`. This aligns with
UVE's standard class and should not affect existing implementations as
both classes serve the same selector purpose.
**Data Attribute Changes**: Analytics data attributes now use standard
UVE naming (`data-dot-*` instead of `data-dot-analytics-*`). The
analytics SDK internally handles reading these attributes, so no
client-side changes are needed.
## Testing
- [x] Unit tests updated for `Contentlet` component
- [x] Unit tests updated for analytics plugins (impression tracker,
identity tracker)
- [x] Removed obsolete analytics state tests
- [x] All tests passing
## Related Issues
Closes #33947
## Additional Notes
This refactoring aligns with the strategy to consolidate analytics
functionality and reduce code duplication across the SDK. Future
enhancements can build on this simplified foundation without managing
separate analytics attribute logic.
The change ensures analytics tracking is always active and consistent,
removing edge cases where analytics might be disabled outside Edit Mode.1 parent 98de141 commit 65e2d0a
File tree
16 files changed
+97
-329
lines changed- core-web/libs/sdk
- analytics
- src/lib/core
- plugin
- identity
- impression
- react/src/lib/next
- __test__/components
- components/Contentlet
- hooks
- types/src/lib/editor
- uve/src
- internal
- lib
- core
- dom
16 files changed
+97
-329
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| |||
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
308 | | - | |
| 307 | + | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
| 189 | + | |
189 | 190 | | |
190 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
Lines changed: 10 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
638 | | - | |
| 638 | + | |
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
675 | | - | |
| 675 | + | |
676 | 676 | | |
677 | 677 | | |
678 | 678 | | |
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
713 | | - | |
| 713 | + | |
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
717 | 717 | | |
718 | | - | |
| 718 | + | |
719 | 719 | | |
720 | 720 | | |
721 | 721 | | |
| |||
Lines changed: 15 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | 22 | | |
28 | 23 | | |
29 | | - | |
| 24 | + | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
| |||
42 | 37 | | |
43 | 38 | | |
44 | 39 | | |
45 | | - | |
46 | 40 | | |
47 | | - | |
48 | 41 | | |
49 | 42 | | |
50 | 43 | | |
51 | | - | |
52 | 44 | | |
53 | | - | |
54 | 45 | | |
55 | 46 | | |
56 | 47 | | |
| |||
64 | 55 | | |
65 | 56 | | |
66 | 57 | | |
| 58 | + | |
67 | 59 | | |
68 | 60 | | |
69 | 61 | | |
| |||
98 | 90 | | |
99 | 91 | | |
100 | 92 | | |
101 | | - | |
| 93 | + | |
| 94 | + | |
102 | 95 | | |
103 | 96 | | |
104 | 97 | | |
105 | 98 | | |
106 | | - | |
| 99 | + | |
107 | 100 | | |
108 | 101 | | |
109 | 102 | | |
| |||
120 | 113 | | |
121 | 114 | | |
122 | 115 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 116 | + | |
126 | 117 | | |
127 | 118 | | |
128 | 119 | | |
129 | 120 | | |
130 | 121 | | |
131 | 122 | | |
132 | 123 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 124 | + | |
| 125 | + | |
137 | 126 | | |
138 | 127 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 128 | + | |
142 | 129 | | |
143 | 130 | | |
144 | 131 | | |
145 | 132 | | |
146 | 133 | | |
147 | 134 | | |
148 | 135 | | |
149 | | - | |
150 | | - | |
| 136 | + | |
| 137 | + | |
151 | 138 | | |
152 | 139 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 140 | + | |
156 | 141 | | |
157 | 142 | | |
158 | 143 | | |
159 | 144 | | |
160 | 145 | | |
161 | 146 | | |
162 | 147 | | |
163 | | - | |
| 148 | + | |
164 | 149 | | |
165 | | - | |
166 | | - | |
167 | 150 | | |
168 | 151 | | |
0 commit comments