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

Ability to pass FACEBOOK_PIXEL_ID directly in template tag #196

Open
ak4zh opened this issue Sep 29, 2021 · 1 comment
Open

Ability to pass FACEBOOK_PIXEL_ID directly in template tag #196

ak4zh opened this issue Sep 29, 2021 · 1 comment

Comments

@ak4zh
Copy link

ak4zh commented Sep 29, 2021

I have one django app hosted with multiple domains and sub-domains, and have different FACEBOOK_PIXEL_ID for all domains.
For I ues request.get_host to deside which css etc to serve for the current request.

Is it possible to allow FACEBOOK_PIXEL_ID to be passed in the tag itself {% facebook_pixel_head FACEBOOK_PIXEL_ID %}

@bittner
Copy link
Member

bittner commented Oct 14, 2022

(Sorry that this answer comes late!)

How do you currently set the FACEBOOK_PIXEL_ID in your application configuration? Wouldn't a simple if-then-else in your project settings module do the trick? e.g.

SITE_PIXELS = {
    "one.example.com": "123",
    "two.example.com": "456",
    "three.example.com": "789",
}
FACEBOOK_PIXEL_ID = SITE_PIXELS.get(request.get_host())

Apparently, the trick here is to get access to the request object. If that doesn't prove to be possible as some suggest you may set FACEBOOK_PIXEL_ID dynamically before the template gets processed, e.g. inside of a context processor you write yourself.

It may be worth to document such an approach in our documentation. Not sure if it makes sense to change the implementation of the template tag. If you think it is, I would suggest to try to find a generic approach for all template tags. (That said, PRs welcome!)

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