How to insert Header Tag Scripts in ERPNext

I want to insert an HTML tag script from Facebook Pixel for my website. But I can’t do so with Website HTML header options, or Website Script Section because the HTML field rejects Javascript and vice-versa with the Javascript field.

Any leads will be highly appreciated.

Actually if we can provide integration for Google Tag Manager we could manage all our scripts from there. This has an added advantage over the current Google Analytics integration:

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TTDGRHK');</script>
<!-- End Google Tag Manager -->

Google Tag Manager overview
Google Tag Manager is a tag management system that allows you to quickly and easily update tags and code snippets on your website or mobile app. Once the Tag Manager snippet has been added to your website or mobile app, you can configure tags via a web-based user interface without having to alter and deploy additional code. This reduces errors and frees you from having to involve a developer whenever you need to make changes.

You can hard code it in the base html template.
You’ll find it in frappe/templates/base.html

Thank you @joelios I need this code to affect only 1 site. I have multiple on this bench instance. Can this method work?

No sorry. The PageGenerator of frappe use for each Website this base template.

If you want to use for a specific site another base template, you can deveop an app and set in the hooks.py of this app the corresponding base template with your script.

Thank you Joelios. That sounds right but Its such a troublesome process to do a simple thing.

I’m totaly agree with you.

What you can try also:
Customise the website Doctype and add a check field called for e.g. “use head script”. I believe this field value should get loaded by the get_context function of the webgenerator. then you could insert your script between the jinja tags “{% if use_head_script == “1” %}” and “{% endif %}” in the base template (“base.html”) of frappe.
If this field effectly get loaded by the get_context function, your code will be insert by the generator only if you checked the check field in the website record.

2 Likes

Thank you. I’ll give it a shot.

can you advise me which website doctype? website Theme is it?

1 Like