Skip to content

Commit 0e5831f

Browse files
bunsenstraatAniket-Engg
authored andcommitted
tracking
1 parent c9a3df0 commit 0e5831f

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

libs/remix-ui/desktop-download/README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import { DesktopDownload } from '@remix-ui/desktop-download'
1919
function MyComponent() {
2020
return (
2121
<div>
22-
{/* Compact layout (default) */}
23-
<DesktopDownload />
22+
{/* Compact layout with tracking */}
23+
<DesktopDownload trackingContext="navbar" />
2424

2525
{/* Full layout */}
26-
<DesktopDownload compact={false} />
26+
<DesktopDownload compact={false} trackingContext="home" />
27+
28+
{/* Span variant for dropdowns */}
29+
<DesktopDownload variant="span" trackingContext="dropdown" />
2730
</div>
2831
)
2932
}
@@ -63,10 +66,29 @@ Perfect for dropdown items or anywhere you need a simple link without button sty
6366

6467
| Prop | Type | Default | Description |
6568
|------|------|---------|-------------|
66-
| `className` | `string` | `''` | Additional CSS classes to apply to the component |
67-
| `compact` | `boolean` | `true` | Whether to use compact single-line layout or full multi-line layout |
68-
| `variant` | `'button' \| 'span'` | `'button'` | Whether to render as a button or as a simple span/link |
69-
| `style` | `React.CSSProperties` | `{}` | Inline styles to apply to the root component |
69+
| `className` | `string` | `''` | Additional CSS classes |
70+
| `compact` | `boolean` | `true` | Use compact layout |
71+
| `variant` | `'button' \| 'span'` | `'button'` | Display variant |
72+
| `style` | `CSSProperties` | `{}` | Inline styles |
73+
| `trackingContext` | `string` | `'unknown'` | Context for Matomo analytics (e.g., 'hometab', 'dropdown', 'navbar') |
74+
75+
## Analytics Tracking
76+
77+
The component includes automatic Matomo analytics tracking for all download interactions. Set the `trackingContext` prop to identify where the component is used:
78+
79+
```tsx
80+
<DesktopDownload trackingContext="hometab" />
81+
```
82+
83+
**Tracking Events:**
84+
- Category: `desktopDownload`
85+
- Action: `{context}-{variant}` (e.g., `hometab-compact`, `dropdown-span`)
86+
- Name: `{platform}-{filename}` or `releases-page` for fallbacks
87+
88+
**Examples:**
89+
- `['trackEvent', 'desktopDownload', 'hometab-compact', 'linux-remix-desktop_1.1.0_amd64.deb']`
90+
- `['trackEvent', 'desktopDownload', 'dropdown-span', 'windows-remix-desktop-1.1.0-setup.exe']`
91+
- `['trackEvent', 'desktopDownload', 'navbar-full-fallback', 'releases-page']`
7092

7193
## Platform Support
7294

libs/remix-ui/desktop-download/lib/desktop-download.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { CustomTooltip } from '@remix-ui/helper'
33
import { FormattedMessage } from 'react-intl'
44
import './desktop-download.css'
55

6+
const _paq = (window._paq = window._paq || []) // eslint-disable-line
7+
68
interface DesktopDownloadProps {
79
className?: string
810
compact?: boolean
9-
variant?: 'button' | 'span'
11+
variant?: 'button' | 'span' | 'auto'
1012
style?: React.CSSProperties
13+
trackingContext?: string // Context for Matomo tracking (e.g., 'hometab', 'dropdown', 'navbar')
1114
}
1215

1316
interface ReleaseAsset {
@@ -35,7 +38,13 @@ const GITHUB_API_URL = 'https://api.github.com/repos/remix-project-org/remix-des
3538
const CACHE_KEY = 'remix-desktop-release-cache'
3639
const CACHE_DURATION = 30 * 60 * 1000 // 30 minutes in milliseconds
3740

38-
export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = '', compact = true, variant = 'button', style = {} }) => {
41+
export const DesktopDownload: React.FC<DesktopDownloadProps> = ({
42+
className = '',
43+
compact = true,
44+
variant = 'button',
45+
style = {},
46+
trackingContext = 'unknown'
47+
}) => {
3948
const [releaseData, setReleaseData] = useState<ReleaseData | null>(null)
4049
const [loading, setLoading] = useState(true)
4150
const [error, setError] = useState<string | null>(null)
@@ -181,6 +190,17 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
181190
}
182191
}
183192

193+
// Track download click events
194+
const trackDownloadClick = (platform?: string, filename?: string, variant?: string) => {
195+
const trackingData = [
196+
'trackEvent',
197+
'desktopDownload',
198+
`${trackingContext}-${variant || 'button'}`,
199+
platform ? `${platform}-${filename}` : 'releases-page'
200+
]
201+
_paq.push(trackingData)
202+
}
203+
184204
// Load release data on component mount
185205
useEffect(() => {
186206
const loadReleaseData = async () => {
@@ -277,6 +297,7 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
277297
style={{ color: 'inherit' }}
278298
onClick={(e) => {
279299
e.stopPropagation()
300+
trackDownloadClick(detectedDownload.platform, detectedDownload.filename, 'span')
280301
// Allow the default link behavior
281302
}}
282303
>
@@ -337,6 +358,7 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
337358
className="btn btn-sm btn-primary d-flex align-items-center gap-2"
338359
target="_blank"
339360
rel="noopener noreferrer"
361+
onClick={() => trackDownloadClick(detectedDownload.platform, detectedDownload.filename, 'compact')}
340362
>
341363
<i className="far fa-desktop"></i>
342364
<span>
@@ -379,6 +401,7 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
379401
className="btn btn-sm btn-primary d-flex align-items-center gap-2"
380402
target="_blank"
381403
rel="noopener noreferrer"
404+
onClick={() => trackDownloadClick(undefined, undefined, 'compact-fallback')}
382405
>
383406
<i className="far fa-desktop"></i>
384407
<span>
@@ -433,6 +456,7 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
433456
className="btn btn-primary d-flex align-items-center gap-2"
434457
target="_blank"
435458
rel="noopener noreferrer"
459+
onClick={() => trackDownloadClick(detectedDownload.platform, detectedDownload.filename, 'full')}
436460
>
437461
<i className={getPlatformIcon(detectedDownload.platform)}></i>
438462
<span>
@@ -471,6 +495,7 @@ export const DesktopDownload: React.FC<DesktopDownloadProps> = ({ className = ''
471495
className="btn btn-primary d-flex align-items-center gap-2"
472496
target="_blank"
473497
rel="noopener noreferrer"
498+
onClick={() => trackDownloadClick(undefined, undefined, 'full-fallback')}
474499
>
475500
<i className="fas fa-external-link-alt"></i>
476501
<span>

libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function HomeTabTitle() {
116116
<a className="btn btn-secondary bg-dark text-decoration-none col-md-5" style={{ fontSize: '0.7rem', minWidth: '125px', color: isDark ? 'white' : 'black' }} href="https://remix-ide.readthedocs.io/en/latest" target="_blank" onClick={() => _paq.push(['trackEvent', 'hometab', 'titleCard', 'documentation'])}><FormattedMessage id="home.documentation" /></a>
117117
<a className="btn btn-secondary bg-dark text-decoration-none col-md-5" style={{ fontSize: '0.7rem', minWidth: '125px', color: isDark ? 'white' : 'black' }} href="https://remix-project.org" target="_blank" onClick={() => _paq.push(['trackEvent', 'hometab', 'titleCard', 'webSite'])}><FormattedMessage id="home.website" /></a>
118118
</div>
119-
<DesktopDownload className='mt-3' compact />
119+
<DesktopDownload className='mt-3' compact trackingContext="hometab" />
120120
</div>
121121
</div>
122122
)

libs/remix-ui/top-bar/src/components/WorkspaceDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const WorkspacesDropdown: React.FC<WorkspacesDropdownProps> = ({ menuItem
328328
</Dropdown.Item>
329329
<Dropdown.Divider className="border mb-0 mt-0 remixui_menuhr" style={{ pointerEvents: 'none' }} />
330330
<Dropdown.Item>
331-
<DesktopDownload style={{ color: '#D678FF' }} variant="span" />
331+
<DesktopDownload style={{ color: '#D678FF' }} variant="span" trackingContext="dropdown" />
332332
</Dropdown.Item>
333333
<Dropdown.Item onClick={() => {
334334
downloadWorkspaces()

0 commit comments

Comments
 (0)