@ossy/analytics 1.10.0 → 1.10.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/analytics",
3
3
  "description": "Analytics module — workspace analytics for website traffic",
4
- "version": "1.10.0",
4
+ "version": "1.10.1",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -23,8 +23,9 @@
23
23
  ],
24
24
  "peerDependencies": {
25
25
  "@ossy/design-system": "*",
26
+ "@ossy/resources": "*",
26
27
  "@ossy/sdk-react": "*",
27
28
  "react": "*"
28
29
  },
29
- "gitHead": "d9d31182be64a448d575da432af2830d909ad4b9"
30
+ "gitHead": "c0ba5d90749690634e4dc2705178ff8d89dd3070"
30
31
  }
@@ -1,5 +1,6 @@
1
1
  import React, { useMemo } from 'react'
2
- import { useWorkspace } from '@ossy/sdk-react'
2
+ import { GetWorkspace } from '@ossy/workspaces'
3
+ import { useSdk } from '@ossy/sdk-react'
3
4
  import { Text, Title, View, useLocale } from '@ossy/design-system'
4
5
  import { usePageViewStats } from './usePageViewStats.js'
5
6
 
@@ -27,7 +28,8 @@ function SummaryCard({ label, value }) {
27
28
 
28
29
  export default function AnalyticsPage() {
29
30
  const { t } = useLocale()
30
- const { workspace } = useWorkspace()
31
+ const sdk = useSdk()
32
+ const { data: workspace } = sdk.read(GetWorkspace)
31
33
  const { from, to } = useMemo(() => {
32
34
  const now = Date.now()
33
35
  return { from: now - 30 * 24 * 60 * 60 * 1000, to: now }
@@ -1,5 +1,5 @@
1
1
  {
2
- "analytics.home.documentTitle": "Analytics",
2
+ "analytics/home.documentTitle": "Analytics",
3
3
  "analytics.home.title": "Analytics",
4
4
  "analytics.home.description": "Workspace analytics for website traffic and top performing pages.",
5
5
  "analytics.home.loading": "Loading analytics...",
@@ -1,5 +1,5 @@
1
1
  {
2
- "analytics.home.documentTitle": "Analys",
2
+ "analytics/home.documentTitle": "Analys",
3
3
  "analytics.home.title": "Analys",
4
4
  "analytics.home.description": "Workspace-analys för webbtrafik och mest besökta sidor.",
5
5
  "analytics.home.loading": "Laddar analys...",
@@ -1,8 +1,9 @@
1
1
  import { useEffect, useMemo, useState } from 'react'
2
-
3
- const API_URL = '/@ossy'
2
+ import { GetPageViewStats } from '@ossy/resources'
3
+ import { useSdk } from '@ossy/sdk-react'
4
4
 
5
5
  export function usePageViewStats({ workspaceId, from, to, limit = 10 }) {
6
+ const sdk = useSdk()
6
7
  const [status, setStatus] = useState('loading')
7
8
  const [data, setData] = useState({
8
9
  totalViews: 0,
@@ -10,28 +11,17 @@ export function usePageViewStats({ workspaceId, from, to, limit = 10 }) {
10
11
  topPaths: [],
11
12
  })
12
13
 
13
- const params = useMemo(() => {
14
- const sp = new URLSearchParams()
15
- if (from) sp.set('from', `${from}`)
16
- if (to) sp.set('to', `${to}`)
17
- if (limit) sp.set('limit', `${limit}`)
18
- return sp.toString()
19
- }, [from, to, limit])
14
+ const payload = useMemo(() => ({
15
+ from,
16
+ to,
17
+ limit,
18
+ }), [from, to, limit])
20
19
 
21
20
  useEffect(() => {
22
21
  if (!workspaceId) return
23
22
 
24
23
  setStatus('loading')
25
- fetch(`${API_URL}/resources/page-views/stats?${params}`, {
26
- method: 'GET',
27
- headers: {
28
- workspaceId,
29
- },
30
- })
31
- .then(res => {
32
- if (!res.ok) return Promise.reject(new Error('Failed to fetch stats'))
33
- return res.json()
34
- })
24
+ sdk.invoke(GetPageViewStats, payload)
35
25
  .then(json => {
36
26
  setData({
37
27
  totalViews: json?.totalViews || 0,
@@ -43,7 +33,7 @@ export function usePageViewStats({ workspaceId, from, to, limit = 10 }) {
43
33
  .catch(() => {
44
34
  setStatus('error')
45
35
  })
46
- }, [workspaceId, params])
36
+ }, [sdk, workspaceId, payload])
47
37
 
48
38
  return {
49
39
  status,