npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-tag-manager

v0.1.2

Published

Easy to use Google Tag Manager implementation for Vue

Downloads

4,705

Readme

Vue Tag Manager

Build Status Coverage Status

Simple Google Tag Manager implementation for Vue

Usage

Simple setup:

import Vue from "vue"
import VueTagManager from "vue-tag-manager"

// Do this before creating the Vue app
Vue.use(VueTagManager, {
    gtmId: 'GTM-XXXXXX'
})

new Vue({...})

Later in app:

Vue.gtm.push({ event: 'some-event' })

// or in a component
this.$gtm.push({ event: 'some-event' })

or in a template:

<button @click="$gtm.push({ event: 'some-event' })">

Configuration Options

| Option | Description | Type | Default | Is Required? | | --------------- | ---------------------------------------------------------------------------------------------------------------- | -------- | ------------- | ------------ | | gtmId | Google Tag Manager ID | string | - | Yes | | queryParams | Additional parameters to add to the script URL, including gtm_preview and gtm_auth for environment switching | object | {} | No | | dataLayer | Initialise the GTM datalayer with variables. | object | undefined | No | | dataLayerName | The Data Layer variable name | string | "dataLayer" | No |

Usage

push(entry: Object)

const entry = {event: 'something'}
this.$gtm.push(entry)
// or
Vue.gtm.push(entry)

On a TagManager instance, this method allows you to push events onto the initialised data layer. See the Google Tag Manager documentation for more details on event tracking with GTM.

Native Implementation

While this library is mainly for Vue, the core Tag Manager is just a javascript object, so it's been exported too. It can be used as such:

<head>
    <script src="https://unpkg.com/[email protected]/lib/TagManager.js"></script>
    <script>
        VueTagManager.initialize({
            gtmId: 'GTM-KG7LSMH'
        })
    </script>
</head>

<!-- In code later -->
<script>
    window.TagManager.push({event: "something"})
</script>

To-do

  • [x] Initital implementation from React GTM
  • [x] Basic Vue Plugin
  • [x] Shell out tests
  • [x] Simplify the URL + snippet generation and injection
  • [x] Vue prototype property
  • [ ] Basic implementation - don't break on SSR
  • [ ] Vue auto-track router
  • [ ] Vue track directive
  • [ ] More through docs with examples
  • [ ] SSR support

Why need another GTM library?

Initially used vue-gtm which is a great library, but wanted to be able to programatically configure the GTMID and initial DataLayer.

Really liked the React GTM script injection dev experience, and liked the Vue GTM dev and track experience (as a Vue Plugin, with the $gtm interface). So this plugin aims to combine both of them into this simple library.

Inspired by