-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from AndroidDagashi/bridge-plugins
- Loading branch information
Showing
8 changed files
with
72 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { defineNuxtPlugin, useRouter } from '#imports' | ||
|
||
const GA_ID = 'UA-116221691-1' | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
return | ||
} | ||
|
||
const newTag = document.createElement('script') | ||
newTag.async = true | ||
newTag.src = `https://www.googletagmanager.com/gtag/js?id=${GA_ID}` | ||
|
||
const existingTag = document.getElementsByTagName('script')[0] | ||
existingTag.parentNode!.insertBefore(newTag, existingTag) | ||
|
||
// @ts-ignore | ||
window.dataLayer = window.dataLayer || [] | ||
function gtag(...args: any[]) { | ||
// @ts-ignore | ||
window.dataLayer.push(args) | ||
} | ||
// @ts-ignore | ||
window.gtag = gtag | ||
|
||
gtag('js', new Date()) | ||
gtag('config', GA_ID) | ||
|
||
const router = useRouter() | ||
router.afterEach((to, _from) => { | ||
gtag('config', GA_ID, { | ||
page_path: to.fullPath, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { Context } from '@nuxt/types' | ||
import { defineNuxtPlugin } from '#imports' | ||
import type { RootState } from '~/store' | ||
|
||
/** | ||
* dispatch `nuxtServerInit` manually if state is not initialized | ||
* https://github.com/nuxt/nuxt.js/issues/7051#issuecomment-604914461 | ||
*/ | ||
export default async function ({ app, store }: Context): Promise<void> { | ||
if (!(store.state as RootState).initialized) { | ||
await store.dispatch('nuxtServerInit', app.context) | ||
export default defineNuxtPlugin(async (nuxtApp) => { | ||
if (!(nuxtApp.$store.state as RootState).initialized) { | ||
await nuxtApp.$store.dispatch('nuxtServerInit', nuxtApp.nuxt2Context) | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CommitOptions, Store } from 'vuex' | ||
|
||
declare module 'vuex' { | ||
interface Commit { | ||
<P = any>(type: string, payload?: P, options?: CommitOptions): void | ||
} | ||
} | ||
|
||
declare module '@nuxt/bridge-schema' { | ||
interface NuxtAppCompat { | ||
$store: Store<any> | ||
} | ||
} |