Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] useTrackMetric doesn't send any data to Application Insights after the latest Teams update (V2) #80

Open
kroudams opened this issue Feb 15, 2024 · 5 comments
Labels

Comments

@kroudams
Copy link

After the recent Teams update (V2)
applicationinsights-react-js -> useTrackMetric has stopped sending
any data to Application Insights.

That's how I use it in my App:

  1. Custom hook that wraps it:
import { useAppInsightsContext, useTrackMetric } from '@microsoft/applicationinsights-react-js';
import { ICustomProperties } from '@microsoft/applicationinsights-web';

export interface IUseTeamsTrackMetric {
    componentName: string;
    customProperties?: ICustomProperties;
}

type UseTeamsTrackMetricReturnType = () => void;

const useTeamsTrackMetric = ({ componentName, customProperties }: IUseTeamsTrackMetric): UseTeamsTrackMetricReturnType => {
    const appInsights = useAppInsightsContext();
    const trackMetric = useTrackMetric(appInsights, componentName, { ...customProperties, telemetryType: 'frontend' });
    return trackMetric;
};

export default useTeamsTrackMetric;

Examples of use:

export const EmailModal: FC<IEmailModalProps> = ({ isOpen }) => {
    const teamsTrackMetric = useTeamsTrackMetric({ componentName: EMAIL_DRAFT_MODAL_COMPONENT_NAME, customProperties: { event: TELEMETRY_EVENT.LOAD } });

    useEffect(() => {
        if (isOpen) {
            teamsTrackMetric();
        }
    }, [isOpen]);

    return (
        <EmailDialog open={isOpen}>
           <EmailDialogContent>...</EmailDialogContent>
        </EmailDialog>
    );
};

export default EmailModal;

export const EmailDialogContent: FC<IEmailDialogContentProps> = ({ body, onCancel, isLoading, isError, onRefresh }) => {
    const trackCopyToClipboardClick = useTeamsTrackEvent({ eventName: 'Copy to clipboard button', componentName: EMAIL_CONTAINER_COMPONENT_NAME });
    const teamsTrackMetric = useTeamsTrackMetric({ componentName: EMAIL_CONTAINER_COMPONENT_NAME, customProperties: { event: TELEMETRY_EVENT.LOAD } });

    const bodyContentLoaded = !isLoading && !isError && body;

    useEffect(() => {
        if (bodyContentLoaded) {
            teamsTrackMetric();
        }
    }, [bodyContentLoaded]);

    if (isLoading) {
        return <Skeleton onCancel={onCancel} />;
    }

    if (isError) {
        return <Error onTryAgain={onRefresh} />;
    }

    const handleClick = () => {
         ...
        trackCopyToClipboardClick({ eventData: { action: TELEMETRY_ACTION.CLICK }, methodName: 'handleClick' });
        ...
    };

    return (
            <EmailDialogContent>
                <EmailDialogBtn click={handleClick }>...</EmailDialogBtn>
           </EmailDialogContent>
    );
};
@MSNev
Copy link
Contributor

MSNev commented Mar 4, 2024

I'm not sure how to help here...

It sounds like the UI / framework that you have been relying on (and the react framework is using) is no longer present in the same form inside of Teams V2???

@kroudams
Copy link
Author

kroudams commented Mar 5, 2024

Might it be a problem with Teams V2 that somehow breaks the implementation of the Telemetry in applicationinsights-react-js? Are you aware of any issues related to the new Teams version?

@MSNev
Copy link
Contributor

MSNev commented Mar 5, 2024

Might it be a problem with Teams V2 that somehow breaks the implementation of the Telemetry in applicationinsights-react-js?

That would be my first thought, but I'm not familiar with UI the framework within a Teams App.

Are you aware of any issues related to the new Teams version?

So no on this one, it maybe that they have changed the version or maybe are using some sort of "shim" to provide the same interfaces with different implementations under the covers??? -- just guessing on this

@cloudsere
Copy link

cloudsere commented Apr 16, 2024

Yes, I think the issue is trackActivity never got called...

image

Copy link

This Issue will be closed in 30 days. Please remove the "Stale" label or comment to avoid closure with no action.

@github-actions github-actions bot added the stale label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants