mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
feat: context/segment usage plausible (#3956)
This commit is contained in:
parent
7b8b6bceaf
commit
4a2867bd78
@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
|
|||||||
import { formatStrategyName } from 'utils/strategyNames';
|
import { formatStrategyName } from 'utils/strategyNames';
|
||||||
import { useStrategiesByContext } from 'hooks/api/getters/useStrategiesByContext/useStrategiesByContext';
|
import { useStrategiesByContext } from 'hooks/api/getters/useStrategiesByContext/useStrategiesByContext';
|
||||||
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
const StyledUl = styled('ul')(({ theme }) => ({
|
const StyledUl = styled('ul')(({ theme }) => ({
|
||||||
listStyle: 'none',
|
listStyle: 'none',
|
||||||
@ -22,6 +23,15 @@ interface IContextFieldUsageProps {
|
|||||||
export const ContextFieldUsage = ({ contextName }: IContextFieldUsageProps) => {
|
export const ContextFieldUsage = ({ contextName }: IContextFieldUsageProps) => {
|
||||||
const { strategies } = useStrategiesByContext(contextName);
|
const { strategies } = useStrategiesByContext(contextName);
|
||||||
const { projects } = useProjects();
|
const { projects } = useProjects();
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
|
const trackClick = () => {
|
||||||
|
trackEvent('context-usage', {
|
||||||
|
props: {
|
||||||
|
eventType: 'context usage viewed',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const projectsUsed = Array.from(
|
const projectsUsed = Array.from(
|
||||||
new Set<string>(
|
new Set<string>(
|
||||||
@ -32,7 +42,7 @@ export const ContextFieldUsage = ({ contextName }: IContextFieldUsageProps) => {
|
|||||||
const projectList = (
|
const projectList = (
|
||||||
<StyledUl>
|
<StyledUl>
|
||||||
{projectsUsed.map(projectId => (
|
{projectsUsed.map(projectId => (
|
||||||
<li key={projectId}>
|
<li key={projectId} onClick={trackClick}>
|
||||||
<Link
|
<Link
|
||||||
to={`/projects/${projectId}`}
|
to={`/projects/${projectId}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
@ -4,6 +4,7 @@ import { IProjectCard } from 'interfaces/project';
|
|||||||
import { IFeatureStrategy } from 'interfaces/strategy';
|
import { IFeatureStrategy } from 'interfaces/strategy';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { formatStrategyName } from 'utils/strategyNames';
|
import { formatStrategyName } from 'utils/strategyNames';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
const StyledUl = styled('ul')(({ theme }) => ({
|
const StyledUl = styled('ul')(({ theme }) => ({
|
||||||
listStyle: 'none',
|
listStyle: 'none',
|
||||||
@ -27,10 +28,19 @@ export const SegmentProjectAlert = ({
|
|||||||
projectsUsed,
|
projectsUsed,
|
||||||
availableProjects,
|
availableProjects,
|
||||||
}: ISegmentProjectAlertProps) => {
|
}: ISegmentProjectAlertProps) => {
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
|
const trackClick = () => {
|
||||||
|
trackEvent('segment-usage', {
|
||||||
|
props: {
|
||||||
|
eventType: 'segment usage viewed',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
const projectList = (
|
const projectList = (
|
||||||
<StyledUl>
|
<StyledUl>
|
||||||
{Array.from(projectsUsed).map(projectId => (
|
{Array.from(projectsUsed).map(projectId => (
|
||||||
<li key={projectId}>
|
<li key={projectId} onClick={trackClick}>
|
||||||
<Link
|
<Link
|
||||||
to={`/projects/${projectId}`}
|
to={`/projects/${projectId}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
@ -37,7 +37,9 @@ export type CustomEvents =
|
|||||||
| 'demo-view-demo-link'
|
| 'demo-view-demo-link'
|
||||||
| 'demo-start-topic'
|
| 'demo-start-topic'
|
||||||
| 'demo-ask-questions'
|
| 'demo-ask-questions'
|
||||||
| 'demo-open-demo-web';
|
| 'demo-open-demo-web'
|
||||||
|
| 'context-usage'
|
||||||
|
| 'segment-usage';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user