Is there any way to add code(for example analytics/tracking code) to a custom post type using a custom field?
For example, give the ability to the user to add an analytics code and have it injected in the post/template if the field is filled. So that it only tracks the specific post.
Hello. Thank you for contacting the Toolset support.
Maybe its a good idea to add a custom field that holds the status like "Show analytics", you can add checkbox or select field with yes and no options and then with the content template you should add a conditional block or shortcode to display that said JS code based on the selected option. Does that makes sense?
I do not see any way as sooner or later it may create issues as it will be JS code you will be trying to save inside database.
Logically or theoretically it should work.
You may want to use the following sandbox site and create a multiline text custom field and try to save the data per post and check if its working as expected.
You can auto-login to the sandbox site using the following link:
- hidden link