Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore firing events upon navigation #2

Closed
IlCallo opened this issue May 6, 2022 · 3 comments
Closed

Explore firing events upon navigation #2

IlCallo opened this issue May 6, 2022 · 3 comments

Comments

@IlCallo
Copy link
Member

IlCallo commented May 6, 2022

Currently tracking scripts only fire events when you first land on the website

@IlCallo
Copy link
Member Author

IlCallo commented May 9, 2022

If needed, adding this code into a boot file should suffice, if a customPageView is correctly set on GTM

// See https://fullstack-tutorials.com/quasar-framework/quasar-framework-google-tag-manager-and-analytics-setup-for-an-spa-website
import { uid } from 'quasar';
import { boot } from 'quasar/wrappers';

function getCid() {
  // We need an unique identifier for this session
  // We store it in a localStorage, but you may use cookies, too
  if (!localStorage.cid) {
    localStorage.cid = uid();
  }
  return localStorage.cid;
}

export function logEvent(category, action, label, value) {
  window.dataLayer.push({
    event: 'customEvent',
    category: category,
    action: action,
    label: label,
    value: value,
    cid: getCid(),
  });
}

export function logPage(path) {
  // Here you can preprocess the path, if needed
  window.dataLayer.push({
    event: 'customPageView',
    path: path,
    cid: getCid(),
  });
}

export default boot(({ router }) => {
  router.afterEach(to => {
    logPage(to.path);
  });
});

/*
Use this to log events:

import { logEvent } from 'src/boot/gtm';
...

logEvent('conversions', 'PurchaseDoneEvent', 'Purchase Done', 99.90);

*/

I also saw this could probably be skipped for page views by using GTM History events: https://www.analyticsmania.com/other-posts/single-page-applications-with-universal-analytics-and-google-tag-manager/

@IlCallo
Copy link
Member Author

IlCallo commented May 9, 2022

@IlCallo
Copy link
Member Author

IlCallo commented May 10, 2022

Fixed into 47f4030

@IlCallo IlCallo closed this as completed May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant