Skip to content

๐Ÿ’ก Feature Request: Allow initializing Pixel IDs after fetching settings from API (not only via runtimeConfig)ย #21

Description

@abdallah-shaltout

Hi ๐Ÿ‘‹

First, thanks a lot for building and maintaining nuxt-meta-pixel โ€” itโ€™s very helpful for integrating Facebook Pixel with Nuxt.

I ran into a limitation with the current design:

The module only supports configuration via runtimeConfig.public.metapixel or ENV variables.

In our use case, each store (or tenant) has its own Pixel IDs stored in a database.

When a user visits a store, we fetch its settings (including pixel.ids) from an API and only then know which Pixel(s) to initialize.

Currently, because the IDs must be known at build/runtime, thereโ€™s no way to dynamically initialize the Pixel after fetching settings.


Suggested Solution

It would be great if the module exposed an API to manually initialize pixels after fetching data.
For example:

const { $fbq, initPixel } = useNuxtApp()

await settingsStore.fetchSettings()

initPixel(settings.pixel.ids, {
  advancedMatching: { em: 'user@example.com' },
  autoConfig: true
})

// From now on we can use $fbq('track', 'PageView') or the helpers
```ts
This would let us:

Keep all the nice features ($fbq, helpers, PageView integration, script injection, etc.)

But still support dynamic initialization after API calls instead of being locked to runtimeConfig.



---

Why is this useful?

Not just for multi-tenant setups โ€” also for any project where pixel configuration is managed in a CMS, database, or admin panel.

Keeps runtime flexibility without needing separate deployments per pixel ID.



---

Alternatives Considered

Implementing our own plugin that loads the meta-pixel library directly and re-implements $fbq, but then we lose the benefits of this Nuxt module.



---

Would you consider adding this kind of API? Iโ€™d be happy to help test or contribute if needed.

Thanks again ๐Ÿ™

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions