Skip to content

Commit

Permalink
Return gtmPlugin from app context (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphazardous authored May 27, 2024
1 parent f1d9389 commit aac8479
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from '@gtm-support/core';
import { GtmSupport as GtmPlugin, loadScript } from '@gtm-support/core';
import type { App, Plugin } from 'vue';
import { nextTick } from 'vue';
import { getCurrentInstance, nextTick } from 'vue';
import type {
ErrorTypes,
NavigationFailure,
Expand Down Expand Up @@ -240,5 +240,9 @@ export default _default;
* @returns The Vue GTM instance if the it was installed, otherwise `undefined`.
*/
export function useGtm(): GtmPlugin | undefined {
return gtmPlugin;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return (
getCurrentInstance()?.appContext?.app?.config?.globalProperties?.$gtm ??
gtmPlugin
);
}

0 comments on commit aac8479

Please sign in to comment.