© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Arjen

Best way to include script

Hi, I've registered a custom script like this:
FilamentAsset::register([
            Js::make('google-maps')->html(new HtmlString('
            <script>
                    (g => {
                        var h, a, k, p = "The Google Maps JavaScript API",
                            c = "google",
                            l = "importLibrary",
                            q = "__ib__",
                            m = document,
                            b = window;
                        b = b[c] || (b[c] = {});
                        var d = b.maps || (b.maps = {}),
                            r = new Set,
                            e = new URLSearchParams,
                            u = () => h || (h = new Promise(async (f, n) => {
                                await (a = m.createElement("script"));
                                e.set("libraries", [...r] + "");
                                for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]);
                                e.set("callback", c + ".maps." + q);
                                a.src = `https://maps.${c}apis.com/maps/api/js?` + e;
                                d[q] = f;
                                a.onerror = () => h = n(Error(p + " could not load."));
                                a.nonce = m.querySelector("script[nonce]")?.nonce || "";
                                m.head.append(a)
                            }));
                        d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))
                    })({
                        key: "",
                        v: "weekly",
                    });
                </script>
            ')),
        ]);
FilamentAsset::register([
            Js::make('google-maps')->html(new HtmlString('
            <script>
                    (g => {
                        var h, a, k, p = "The Google Maps JavaScript API",
                            c = "google",
                            l = "importLibrary",
                            q = "__ib__",
                            m = document,
                            b = window;
                        b = b[c] || (b[c] = {});
                        var d = b.maps || (b.maps = {}),
                            r = new Set,
                            e = new URLSearchParams,
                            u = () => h || (h = new Promise(async (f, n) => {
                                await (a = m.createElement("script"));
                                e.set("libraries", [...r] + "");
                                for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]);
                                e.set("callback", c + ".maps." + q);
                                a.src = `https://maps.${c}apis.com/maps/api/js?` + e;
                                d[q] = f;
                                a.onerror = () => h = n(Error(p + " could not load."));
                                a.nonce = m.querySelector("script[nonce]")?.nonce || "";
                                m.head.append(a)
                            }));
                        d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))
                    })({
                        key: "",
                        v: "weekly",
                    });
                </script>
            ')),
        ]);

This works, but running
php artisan filament:assets
php artisan filament:assets
produces the following type error
Filament\Support\Assets\Asset::getPath(): Return value must be of type string, null returned
Filament\Support\Assets\Asset::getPath(): Return value must be of type string, null returned
...
Solution
I did it this way for tracking analytics:
        FilamentView::registerRenderHook(
            'panels::body.end',
            static fn (): View => view('analytics'),
        );
        FilamentView::registerRenderHook(
            'panels::body.end',
            static fn (): View => view('analytics'),
        );

and then created view file analytics.blade.php to contain my js
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Best way to color text
FilamentFFilament / ❓┊help
2mo ago
Best way to validate Repeater
FilamentFFilament / ❓┊help
3y ago
Best way to prepare pricing page
FilamentFFilament / ❓┊help
3y ago
Best way to add select to header?
FilamentFFilament / ❓┊help
3y ago