-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Redirecting to a download in an Action within a modal causes the modal to reopen on next close #15141
Comments
You should be able to use URL with a closure? ->extraModalFooterActions([
Action::make('download')
->url(fn($record) => 'https://central.github.com/deployments/desktop/desktop/latest/win32')
->openUrlInNewTab(),
]) |
The problem is the url method runs on page load so the link tracking I'm trying to implement is triggered on page load as well, which makes the data unusable. Additionally, using the url method seems to ignore the action method. That makes sense since it's probably an action underneath but means I have no hook for the code I need to run. |
But the url isn't accessed on page load.... |
Tested locally in my project, and the url method is being triggered when the modal is opened. So not page load, but still before I need it to trigger. |
the url should be loaded but not opened, tracking should only work on a page load. Unless you are tracking for where the url is loaded in the DOM |
I need to track when the url is accessed. This is a Download button, and we want to know how many people have downloaded the content item. By putting the tracking code in the url method, it gets run when the modal is opened which does not mean they have actually accessed the button yet. When using the url method, the action method is ignored, which is where I would put the tracking code if it was still run. Where can I place my tracking code so that it is run when the button is actually pressed?
|
So that’s why, you are tracking based on a php function in a closure which
is evaluated on load.
What you should be doing is adding a tracking id to the url for instance,
or when the url is used you track that on load. Opposed to using php
function for on click.
I presume this is a url not hosted by you?
…On Mon, 6 Jan 2025 at 17:06, Andrew Hamilton ***@***.***> wrote:
I need to track when the url is accessed. This is a Download button, and
we want to know how many people have downloaded the content item. By
putting the tracking code in the url method, it gets run when the modal is
opened which does not mean they have actually accessed the button yet. When
using the url method, the action method is ignored, which is where I would
put the tracking code if it was still run. Where can I place my tracking
code so that it is run when the button is actually pressed?
// This runs the tracking code when the modal is loaded, assuming to prep the URL
->url(function() {myTrackingCode(); return 'https://url.com';})
// This doesn't run the action()
->url('https://url.com')->action(function() {myTrackingCode();})
—
Reply to this email directly, view it on GitHub
<#15141 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKWBFXOFBQTWU2QA73CFED2JKZYTAVCNFSM6AAAAABT5ZTUJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZTGUZTIMRQHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
These URLs are not hosted by us, correct. That would be the optimum solution if we had access. I can alternatively make my own endpoint to do the tracking and then redirect but that feels much more like a workaround when the code I'm currently using works fine otherwise. I don't see using $this->redirect() where I did as bad code. |
So why not add a JS function to the app, and add extra attributes to the
button? Onclick trigger the js function to track it
Many thanks
Tony
…On Tue, 7 Jan 2025 at 20:05, Andrew Hamilton ***@***.***> wrote:
These URLs are not hosted by us, correct. That would be the optimum
solution if we had access.
I can alternatively make my own endpoint to do the tracking and then
redirect but that feels much more like a workaround when the code I'm
currently using works fine otherwise. I don't see using $this->redirect()
where I did as bad code.
—
Reply to this email directly, view it on GitHub
<#15141 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKWBFU2MEXUJVO37RDTMOT2JQXQZAVCNFSM6AAAAABT5ZTUJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZWGEZDQNBZHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Using JS to track things like that is ineffective when users have the ability to block actions in modern browsers. This is a bug, but I'm assuming I will need to patch it myself if I want to see it fixed. |
Package
filament/filament
Package Version
v3.2.131
Laravel Version
v11.36.1
Livewire Version
v3.5.12
PHP Version
PHP 8.3.14
Problem description
After clicking on an Action that is set to redirect to a download attachment URL (that will open the download dialog) inside a modal, then closing the modal, the modal reopens one time.
Expected behavior
That the modal does not reopen at all.
Steps to reproduce
In the reproduction repository:
composer install
,php artisan key:generate
,php artisan migrate --seed
/admin
[email protected]
passwordtest
The related code is in
app/Filament/Pages/Test.php
:Reproduction repository (issue will be closed if this is not valid)
https://github.com/ahamilton9/filament-issue
Relevant log output
No response
The text was updated successfully, but these errors were encountered: