{"id":17967535,"url":"https://github.com/gtm-support/vue-gtm","last_synced_at":"2025-05-16T11:06:02.224Z","repository":{"id":37080361,"uuid":"361124030","full_name":"gtm-support/vue-gtm","owner":"gtm-support","description":"Simple implementation of Google Tag Manager for Vue","archived":false,"fork":false,"pushed_at":"2024-08-23T17:30:05.000Z","size":817,"stargazers_count":223,"open_issues_count":12,"forks_count":27,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-09T10:19:50.383Z","etag":null,"topics":["google","google-tag-manager","googletagmanager","gtm","tracking","typescript","vue","vue2","vue3","vuejs","vuejs2","vuejs3"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@gtm-support/vue-gtm","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gtm-support.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Shinigami92"],"custom":["https://www.paypal.com/donate?hosted_button_id=L7GY729FBKTZY"]}},"created_at":"2021-04-24T09:43:01.000Z","updated_at":"2025-05-02T23:02:57.000Z","dependencies_parsed_at":"2024-01-01T13:56:26.985Z","dependency_job_id":"ed190694-dcae-4379-94a9-1ee877918078","html_url":"https://github.com/gtm-support/vue-gtm","commit_stats":{"total_commits":77,"total_committers":9,"mean_commits":8.555555555555555,"dds":0.2727272727272727,"last_synced_commit":"18fd3374ac4a970c12aaa1cae97ae43b82a0fd6f"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtm-support%2Fvue-gtm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtm-support%2Fvue-gtm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtm-support%2Fvue-gtm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gtm-support%2Fvue-gtm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gtm-support","download_url":"https://codeload.github.com/gtm-support/vue-gtm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google","google-tag-manager","googletagmanager","gtm","tracking","typescript","vue","vue2","vue3","vuejs","vuejs2","vuejs3"],"created_at":"2024-10-29T14:09:04.285Z","updated_at":"2025-05-16T11:05:57.203Z","avatar_url":"https://github.com/gtm-support.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Shinigami92","https://www.paypal.com/donate?hosted_button_id=L7GY729FBKTZY"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eVue Google Tag Manager\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://tagmanager.google.com/\"\u003e\n    \u003cimg alt=\"Google Tag Manager\" src=\"https://www.gstatic.cn/analytics-suite/header/suite/v2/ic_tag_manager.svg\" height=\"192\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://vuejs.org/\"\u003e\n    \u003cimg alt=\"Vue.js\" src=\"https://vuejs.org/images/logo.png\" height=\"192\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch4 align=\"center\"\u003eSimple implementation of Google Tag Manager in Vue.js\u003c/h4\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/gtm-support/vue-gtm/blob/main/LICENSE\"\u003e\n    \u003cimg alt=\"license: MIT\" src=\"https://img.shields.io/github/license/gtm-support/vue-gtm.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@gtm-support/vue-gtm\"\u003e\n    \u003cimg alt=\"NPM package\" src=\"https://img.shields.io/npm/v/@gtm-support/vue-gtm.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@gtm-support/vue-gtm\"\u003e\n    \u003cimg alt=\"downloads\" src=\"https://img.shields.io/npm/dt/@gtm-support/vue-gtm.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"code style: Prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/gtm-support/vue-gtm/actions/workflows/ci.yml\"\u003e\n    \u003cimg alt=\"Build Status\" src=\"https://github.com/gtm-support/vue-gtm/actions/workflows/ci.yml/badge.svg?branch=main\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nThis plugin will help you in your common GTM tasks.\n\n**Note: If you are looking to track all Vuex mutations, you can use [Vuex GTM plugin](https://gist.github.com/matt-e-king/ebdb39088c50b96bbbbe77c5bc8abb2b)**\n\n# Requirements\n\n- **Vue.** \u003e= 3.0.0\n- **Google Tag Manager account.** To send data to\n\n**Optional dependencies**\n\n- **Vue Router** \u003e= 4.x - In order to use auto-tracking of screens\n\n# Configuration\n\n`npm install @gtm-support/vue-gtm`\n\nHere is an example configuration:\n\n```js\nimport { createApp } from 'vue';\nimport { createGtm } from '@gtm-support/vue-gtm';\nimport router from './router';\n\nconst app = createApp(App);\n\napp.use(router);\n\napp.use(\n  createGtm({\n    id: 'GTM-xxxxxx', // Your GTM single container ID, array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy'] or array of objects [{id: 'GTM-xxxxxx', queryParams: { gtm_auth: 'abc123', gtm_preview: 'env-4', gtm_cookies_win: 'x'}}, {id: 'GTM-yyyyyy', queryParams: {gtm_auth: 'abc234', gtm_preview: 'env-5', gtm_cookies_win: 'x'}}], // Your GTM single container ID or array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy']\n    queryParams: {\n      // Add URL query string when loading gtm.js with GTM ID (required when using custom environments)\n      gtm_auth: 'AB7cDEf3GHIjkl-MnOP8qr',\n      gtm_preview: 'env-4',\n      gtm_cookies_win: 'x',\n    },\n    source: 'https://customurl.com/gtm.js', // Add your own serverside GTM script\n    defer: false, // Script can be set to `defer` to speed up page load at the cost of less accurate results (in case visitor leaves before script is loaded, which is unlikely but possible). Defaults to false, so the script is loaded `async` by default\n    compatibility: false, // Will add `async` and `defer` to the script tag to not block requests for old browsers that do not support `async`\n    nonce: '2726c7f26c', // Will add `nonce` to the script tag\n    enabled: true, // defaults to true. Plugin can be disabled by setting this to false for Ex: enabled: !!GDPR_Cookie (optional)\n    debug: true, // Whether or not display console logs debugs (optional)\n    loadScript: true, // Whether or not to load the GTM Script (Helpful if you are including GTM manually, but need the dataLayer functionality in your components) (optional)\n    vueRouter: router, // Pass the router instance to automatically sync with router (optional)\n    ignoredViews: ['homepage'], // Don't trigger events for specified router names (optional)\n    trackOnNextTick: false, // Whether or not call trackView in Vue.nextTick\n  }),\n);\n```\n\nThis injects the tag manager script in the page, except when `enabled` is set to `false`.\nIn that case it will be injected when calling `this.$gtm.enable(true)` for the first time.\n\nRemember to enable the History Change Trigger for router changes to be sent through GTM.\n\n# Documentation\n\nOnce the configuration is completed, you can access vue gtm instance in your components like that:\n\n```js\nexport default {\n  name: 'MyComponent',\n  data() {\n    return {\n      someData: false,\n    };\n  },\n  methods: {\n    onClick() {\n      this.$gtm.trackEvent({\n        event: null, // Event type [default = 'interaction'] (Optional)\n        category: 'Calculator',\n        action: 'click',\n        label: 'Home page SIP calculator',\n        value: 5000,\n        noninteraction: false, // Optional\n      });\n    },\n  },\n  mounted() {\n    this.$gtm.trackView('MyScreenName', 'currentPath');\n  },\n};\n```\n\nThe passed variables are mapped with GTM data layer as follows\n\n```js\ndataLayer.push({\n  event: event || 'interaction',\n  target: category,\n  action: action,\n  'target-properties': label,\n  value: value,\n  'interaction-type': noninteraction,\n  ...rest,\n});\n```\n\nYou can also access the instance anywhere whenever you imported `Vue` by using `Vue.gtm`. It is especially useful when you are in a store module or somewhere else than a component's scope.\n\nIt's also possible to send completely custom data to GTM with just pushing something manually to `dataLayer`:\n\n```js\nif (this.$gtm.enabled()) {\n  window.dataLayer?.push({\n    event: 'myEvent',\n    // further parameters\n  });\n}\n```\n\n## Sync gtm with your router\n\nThanks to vue-router guards, you can automatically dispatch new screen views on router change!\nTo use this feature, you just need to inject the router instance on plugin initialization.\n\nThis feature will generate the view name according to a priority rule:\n\n- If you defined a meta field for your route named `gtm` this will take the value of this field for the view name.\n- Otherwise, if the plugin don't have a value for the `meta.gtm` it will fallback to the internal route name.\n\nMost of the time the second case is enough, but sometimes you want to have more control on what is sent, this is where the first rule shine.\n\nExample:\n\n```js\nconst myRoute = {\n  path: 'myRoute',\n  name: 'MyRouteName',\n  component: SomeComponent,\n  meta: { gtm: 'MyCustomValue' },\n};\n```\n\n\u003e This will use `MyCustomValue` as the view name.\n\n### Passing custom properties with page view events\n\nIf your GTM setup expects custom data to be sent as part of your page views, you can add desired properties to your route definitions via the `meta.gtmAdditionalEventData` property.\n\nExample:\n\n```js\nconst myRoute = {\n  path: 'myRoute',\n  name: 'myRouteName',\n  component: SomeComponent,\n  meta: { gtmAdditionalEventData: { routeCategory: 'INFO' } },\n};\n```\n\n\u003e This sends the property `routeCategory` with the value 'INFO' as part of your page view event for that route.\n\nNote that the properties `event`, `content-name` and `content-view-name` are always overridden.\n\n### Passing dynamic properties with page view events\n\nIf you need to pass dynamic properties as part of your page views, you can set a callback that derives the custom data after navigation.\n\nExample:\n\n```js\ncreateGtm({\n  // ...other options\n  vueRouter: router,\n  vueRouterAdditionalEventData: () =\u003e ({\n    someComputedProperty: computeProperty(),\n  }),\n});\n```\n\n\u003e This computes and sends the property `someComputedProperty` as part of your page view event after every navigation.\n\nNote that a property with the same name on route level will override this.\n\n## Using with composition API\n\nIn order to use this plugin with composition API (inside your `setup` method), you can just call the custom composable `useGtm`.\n\nExample:\n\n```vue\n\u003ctemplate\u003e\n  \u003cbutton @click=\"triggerEvent\"\u003eTrigger event!\u003c/button\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport { useGtm } from '@gtm-support/vue-gtm';\n\nexport default {\n  name: 'MyCustomComponent',\n\n  setup() {\n    const gtm = useGtm();\n\n    function triggerEvent() {\n      gtm.trackEvent({\n        event: 'event name',\n        category: 'category',\n        action: 'click',\n        label: 'My custom component trigger',\n        value: 5000,\n        noninteraction: false,\n      });\n    }\n\n    return {\n      triggerEvent,\n    };\n  },\n};\n\u003c/script\u003e\n```\n\n## Methods\n\n### Enable plugin\n\nCheck if plugin is enabled\n\n```js\nthis.$gtm.enabled();\n```\n\nEnable plugin\n\n```js\nthis.$gtm.enable(true);\n```\n\nDisable plugin\n\n```js\nthis.$gtm.enable(false);\n```\n\n### Debug plugin\n\nCheck if plugin is in debug mode\n\n```js\nthis.$gtm.debugEnabled();\n```\n\nEnable debug mode\n\n```js\nthis.$gtm.debug(true);\n```\n\nDisable debug mode\n\n```js\nthis.$gtm.debug(false);\n```\n\n## Credits\n\n- [mib200 vue-gtm](https://github.com/mib200/vue-gtm)\n- [ScreamZ vue-analytics](https://github.com/ScreamZ/vue-analytics)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgtm-support%2Fvue-gtm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgtm-support%2Fvue-gtm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgtm-support%2Fvue-gtm/lists"}