Skip to content

Commit aac8479

Browse files
Return gtmPlugin from app context (#409)
1 parent f1d9389 commit aac8479

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
} from '@gtm-support/core';
77
import { GtmSupport as GtmPlugin, loadScript } from '@gtm-support/core';
88
import type { App, Plugin } from 'vue';
9-
import { nextTick } from 'vue';
9+
import { getCurrentInstance, nextTick } from 'vue';
1010
import type {
1111
ErrorTypes,
1212
NavigationFailure,
@@ -240,5 +240,9 @@ export default _default;
240240
* @returns The Vue GTM instance if the it was installed, otherwise `undefined`.
241241
*/
242242
export function useGtm(): GtmPlugin | undefined {
243-
return gtmPlugin;
243+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
244+
return (
245+
getCurrentInstance()?.appContext?.app?.config?.globalProperties?.$gtm ??
246+
gtmPlugin
247+
);
244248
}

0 commit comments

Comments
 (0)