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

@dreamonkey/quasar-app-extension-tracking

v0.1.2

Published

Provide composables to add multiple tracking scripts via Quasar Meta plugin

Downloads

31

Readme

@dreamonkey/quasar-app-extension-tracking

This is a Quasar App Extension (AE) It provides composables for many commonly used tracking scripts using Quasar Meta Composable.

  • Google Tag Manager -> useGoogleTagManager
  • Facebook Pixel -> useFacebookPixel
  • Linkedin Insight Tag -> useLinkedinInsightTag

We'll gladly accept other contributions.

Install

quasar ext add @dreamonkey/tracking

Uninstall

quasar ext remove @dreamonkey/tracking

Usage

Composables are meant to be placed into your layout components, as you usually want them to be triggered each time a user land on any of your pages. All composables accept an id/key, either as a plain string or as a ref. When using a ref, the script won't be added when its value is an empty string, undefined or any falsy value.

Scripts won't be added at all when compiling the app in development mode (eg. when running quasar dev)

// src/layouts/main-layout.vue

import {
  useGoogleTagManager,
  useLinkedinInsightTag,
} from "@dreamonkey/quasar-app-extension-tracking";

export default {
  name: "MainLayout",
  setup() {
    // Add Google Tag Manager script
    useGoogleTagManager("GTM-XXXXXXX");

    const linkedinId = ref();
    // Won't add the Linkedin Insight Tag script since the provided ref has undefined value
    useLinkedinInsightTag(linkedinId);

    // Tracking AE will react to the change and add Linkedin Insight Tag script
    linkedinId.value = "XXXXXXX";
  },
};

Helpers

We provide some helpers to make your life easier.

logGoogleTagManagerEvent

You can use this helper to log an event to Google Tag Manager. We don't make assumption about the event name nor data, but you must assure that the event name is a valid Google Tag Manager event name. The first time you log an event we generate a unique id which identifies the session. The id is then saved into the browser local storage and automatically attached to each event as a cid property.

// Send a lead generation event
logGoogleTagManagerEvent("leadGeneration", {
  leadId: "12345",
});

// { event: "leadGeneration", leadId: "12345", cid: "XXXX-XX...XXX" }

For SPA websites or SSR/SSG with SPA takeover, Google Tag Manager will only catch the first PageView event. To record all page views of subsequent navigations, you need to create an ad-hoc custom event on Google Tag Manager and use router's afterEach hook to fire it upon navigation.

// main-layout.vue - setup()

// Send a page view event each time the user navigate
const router = useRouter();
router.afterEach((to) => {
  logGoogleTagManagerEvent("customPageView", {
    path: to.path,
  });
});

// { event: "customPageView", path: "/homepage", cid: "XXXX-XX...XXX" }

In case you need to provide the page title too and you're using Quasar Meta Composable to update it accordingly to the loaded page, remember that Vue-Router isn't aware of that change and you'll need to add a delay to let the update occour.

// main-layout.vue - setup()

// Send a page view event each time the user navigate
const router = useRouter();
router.afterEach(async (to) => {
  // Wait for Meta plugin to kick in and update the document title
  await new Promise((resolve) => setTimeout(resolve, 500));
  logGoogleTagManagerEvent("customPageView", {
    path: to.path,
    title: document.title,
  });
});

// { event: "customPageView", path: "/homepage", title: "Homepage - My Website",  cid: "XXXX-XX...XXX" }

You can also use Google Tag Manager "History Change" listener instead.

Similar work

  • https://github.com/gtm-support/vue-gtm: much more complete on GTM side, we may copy over some features at some point

Donate

If you appreciate the work that went into this App Extension, please consider donating to Dreamonkey.