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

Automated events prevent links from opening #51

Open
pavish opened this issue Jan 30, 2025 · 2 comments
Open

Automated events prevent links from opening #51

pavish opened this issue Jan 30, 2025 · 2 comments

Comments

@pavish
Copy link

pavish commented Jan 30, 2025

We have automated events enabled in our website mathesar.org.

I noticed that the anchor buttons don't seem to perform navigation on our site in UAE, where I'm currently residing. This is because the click events are prevented, and the navigation is assigned to a callback which happens only when the event is sent i.e when the image 'simple.gif' loads or if an error is thrown, both of which don't seem to be triggering the callback.

Here's an issue in our repo with more details: mathesar-foundation/mathesar-website#127

Update:

Strike my initial reasoning, I went through the auto-events code and found this:

      var callback = function () {
        if (!sent && !element.hasAttribute("target"))
          document.location = element.getAttribute("href");
        sent = true;
      };

The anchor links in our site, had target attributes for _self.

<a ... target="_self" href="...">

This prevented the callback from being called, since they had a target attribute.

And since the onClick event returns false, chrome did not navigate to the href. Somehow, some versions of Firefox seemed to work.

@adriaandotcom
Copy link
Collaborator

Thanks! Is it expected behaviour to always return true for these onClick handlers?

We can fix this in two ways:

  1. Return true for Simple Analytics' onClick handler
  2. Test for if (!sent && element.getAttribute("target") !== "_blank")

What do you think is best?

@pavish
Copy link
Author

pavish commented Feb 12, 2025

My opinion on this:

  1. Do not return false as this would prevent the browser from doing it's default action.
  2. Do not have the redirection logic in the callback. Infact, the entire callback function below is not required.
     var callback = function () {
        if (!sent && !element.hasAttribute("target"))
          document.location = element.getAttribute("href");
        sent = true;
      };
    

The window.saAutomatedLink function would be called first and the analytics request would be sent (call for loading the simple.gif) before the browser handles the redirection.

The sites using auto-events don't really have to wait for the callback to be completed.

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

2 participants