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

cleanUrlTracker temperamental #254

Open
LouiseReid opened this issue Jan 24, 2020 · 0 comments
Open

cleanUrlTracker temperamental #254

LouiseReid opened this issue Jan 24, 2020 · 0 comments

Comments

@LouiseReid
Copy link

I'm using cleanUrlTracker to remove dynamic url props from the url in my React single page app which uses reach router for navigation.

I have this within the script tag in index.html

      ga("create", "UA-xxxxx-xx", "auto");
      ga("require", "cleanUrlTracker", {
        stripQuery: true,
        queryDimensionIndex: 1,
        indexFilename: "index.html",
        trailingSlash: "remove",
        urlFieldsFilter(fieldsObj, parseUrl) {
          const path = parseUrl(fieldsObj.page).pathname;
          const withUsrAndId = /(\/user\/)(?=.*\d)(?=.*[A-Z])[A-Z0-9]{8}(\/id\/)(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}/;
          const withUsr = /(\/user\/)(?=.*\d)(?=.*[A-Z])[A-Z0-9]{8}/;
          if (path.match(withUsrAndId)) {
            fieldsObj.page = path.replace(
              withUsrAndId,
              "$1<user>$2<id>"
            );
          } else if (path.match(withUsr)) {
            fieldsObj.page = path.replace(withUsr, "$1<user>");
          }
          return fieldsObj;
        }
      });
      ga("send", "pageview");

The user param is an 8 digit alpha numeric code and the id is a guid.

I also have this code attached to reach routers history

  const reachHistory = createReachHistory(store);

  reachHistory.listen(page => {
    window.ga("set", "page", page.location.pathname);
    window.ga("send", "pageview", {
      page: page.location.pathname
    });
  });

This code works, but only sometimes and I can't seem to alienate what is causing it to work sometimes and not others. I can sometimes navigate through the whole app where the urls are being replaced and other times it will show the ids half way through.

Is this the correct implementation?

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