{"id":99140,"date":"2025-02-20T09:25:03","date_gmt":"2025-02-20T09:25:03","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/gtmtips-create-facebook-pixel-custom-tag-template\/"},"modified":"2025-02-20T09:25:03","modified_gmt":"2025-02-20T09:25:03","slug":"gtmtips-create-facebook-pixel-custom-tag-template","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=99140","title":{"rendered":"#GTMTips: Create Facebook Pixel Custom Tag Template"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>After the recent release of <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/\">Custom Templates<\/a> for <a href=\"https:\/\/tagmanager.google.com\/\">Google Tag Manager<\/a>, my mind has been occupied by very little else. However, I have a nagging feeling that due to how involved the feature set is, there\u2019s still a lot of demystifying that needs to take place before templates are fully embraced by the GTM user base.<\/p>\n<p>In this article, I want to show you a concrete example of template creation. It\u2019s going to be much more ambitious than the simple <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#tag-template-walkthrough\">walkthrough<\/a> I explored in the <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/\">main guide<\/a>. This time, we\u2019ll step through creating an actual, functional template that caters to a very specific use case: the <a href=\"https:\/\/developers.facebook.com\/docs\/facebook-pixel\/implementation\/\">Facebook Pixel<\/a>.<\/p>\n<blockquote>\n<p>This article is <strong>not<\/strong> endorsed by Facebook or supported by them in any capacity, official or unofficial.<\/p>\n<\/blockquote>\n<p>We\u2019ll stop short of having a perfect representation of the Facebook pixel. However, you\u2019ll have all the tools necessary to extend the template to cover all the features you might need and to replicate it with some other third-party vendor code.<\/p>\n<p>To sweeten the deal, I\u2019ve also created <a href=\"https:\/\/youtu.be\/5ESEtwq7fxc\">a video<\/a> that goes through the motions, in case it\u2019s easier to follow the steps that way.<\/p>\n<p>\n  <iframe src=\"https:\/\/www.youtube-nocookie.com\/embed\/5ESEtwq7fxc?enablejsapi=1\" style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;\" allowfullscreen=\"\" title=\"YouTube Video\"><\/iframe>\n<\/p>\n<p>I want to give special thanks <strong>Eric Burley<\/strong> from Google for walking me through some of the intricacies of template APIs.<\/p>\n<blockquote>\n<p>OK, OK, I <strong>have<\/strong> actually created the full, feature-ready Facebook Pixel Template for you to enjoy. You can find it in <a href=\"https:\/\/github.com\/sahava\/GoogleTagManagerTemplates\">this GitHub repository<\/a>.<\/p>\n<\/blockquote>\n<p>                <span class=\"simmer\"><br \/>\n  <span class=\"close\">X<\/span><\/p>\n<p>\n    <span class=\"fa fa-md fa-bell\"\/><br \/>\n    <strong>The Simmer Newsletter<\/strong>\n  <\/p>\n<p>\n    Subscribe to the <a href=\"https:\/\/www.simoahava.com\/newsletter\/\">Simmer newsletter<\/a> to get the latest news and content from Simo Ahava into your email inbox!\n  <\/p>\n<p>  <\/span><\/p>\n<h2 id=\"tip-99-create-a-facebook-pixel-template\">Tip 99: Create a Facebook Pixel template<\/h2>\n<div style=\"aspect-ratio: 960 \/ 540;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/create-facebook-pixel-template.jpg\" title=\"Create Facebook Pixel template\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"540\" width=\"960\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/create-facebook-pixel-template.jpg#ZgotmplZ\" alt=\"Create Facebook Pixel template\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p><strong>You can download the template export file <a href=\"https:\/\/gist.github.com\/sahava\/212fdbb6cd4d250fa97eeaa8ba693913\">here<\/a><\/strong>. Read <a href=\"https:\/\/gist.github.com\/sahava\/212fdbb6cd4d250fa97eeaa8ba693913\">this<\/a> to find out how to import it into your custom templates. You don\u2019t <strong>have<\/strong> to use the export file, but it might make it easier to walk through the rest of the article.<\/p>\n<p><!-- toc --><\/p>\n<h3 id=\"what-youll-end-up-with\">What you\u2019ll end up with<\/h3>\n<div style=\"aspect-ratio: 1798 \/ 1398;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-pixel-template.jpg\" title=\"Facebook pixel template\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1398\" width=\"1798\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-pixel-template.jpg#ZgotmplZ\" alt=\"Facebook pixel template\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The template has the following features:<\/p>\n<ol>\n<li>\n<p>Ability to add multiple Pixel IDs, comma-separated. The tag hit will be sent to all the Pixel IDs you specify in the list.<\/p>\n<\/li>\n<li>\n<p>Support for four events: <strong>PageView<\/strong>, <strong>Lead<\/strong>, <strong>CompleteRegistration<\/strong>, and <strong>Custom<\/strong> (the Custom event will let you specify the event name in a text field that appears).<\/p>\n<\/li>\n<li>\n<p>Possibility to add any Object Properties to the hit.<\/p>\n<\/li>\n<li>\n<p>You can check a box to disable the <a href=\"https:\/\/developers.facebook.com\/docs\/facebook-pixel\/advanced#automatic-configuration\">Automatic Configuration<\/a> of the pixel.<\/p>\n<\/li>\n<\/ol>\n<h3 id=\"step-1-add-template-information\">Step 1: Add template information<\/h3>\n<p>After creating a new template, this is what the <strong>Info<\/strong> screen looks like. Remember to enable <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#advanced-settings\"><strong>Advanced Settings<\/strong><\/a> for the editor so that you can edit the <strong>Brand Name<\/strong> field.<\/p>\n<div style=\"aspect-ratio: 862 \/ 752;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-info.jpg\" title=\"Facebook info screen\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"752\" width=\"862\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-info.jpg#ZgotmplZ\" alt=\"Facebook info screen\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h3 id=\"step-2-add-fields\">Step 2: Add fields<\/h3>\n<p>The template will have <strong>four<\/strong> fields.<\/p>\n<h4 id=\"field-1-text-input-named-pixelid\">Field 1: Text Input named <code>pixelId<\/code><\/h4>\n<div style=\"aspect-ratio: 1882 \/ 1004;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/pixelid-field.jpg\" title=\"Pixel ID field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1004\" width=\"1882\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/pixelid-field.jpg#ZgotmplZ\" alt=\"Pixel ID field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Make sure the following <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#field-configuration\">field configurations<\/a> are enabled for the <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#text-input\"><strong>Text Input<\/strong><\/a> field:<\/p>\n<ol>\n<li>\n<p><strong>Always in summary<\/strong>: Checked<\/p>\n<\/li>\n<li>\n<p><strong>Display name<\/strong>: <code>Facebook Pixel ID(s)<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Validation rules<\/strong>: (see below)<\/p>\n<\/li>\n<li>\n<p><strong>Value hint<\/strong>: <code>e.g. 12345678910<\/code><\/p>\n<\/li>\n<\/ol>\n<p>For the <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#validation-rules\">validation rules<\/a>, add two different rules:<\/p>\n<ol>\n<li>\n<p><strong>This value cannot be empty<\/strong>, with Error message <code>You must provide a Pixel ID<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>This value must match a regular expression<\/strong>, with value <code>^[0-9,]+$<\/code>, and Error message <code>Invalid Pixel ID format<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p>You can find the Error message by clicking to show <strong>Advanced Settings<\/strong> for each Validation rule.<\/p>\n<div style=\"aspect-ratio: 1896 \/ 712;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/eventname-field.jpg\" title=\"Eventname field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"712\" width=\"1896\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/eventname-field.jpg#ZgotmplZ\" alt=\"Eventname field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Make sure the following <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#field-configuration\">field configurations<\/a> are enabled for the <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#drop-down-menu\"><strong>Text Input<\/strong><\/a> field:<\/p>\n<ol>\n<li>\n<p><strong>Always in summary<\/strong>: Checked<\/p>\n<\/li>\n<li>\n<p><strong>Display name<\/strong>: <code>Event Name<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Nested fields<\/strong>: (see below)<\/p>\n<\/li>\n<\/ol>\n<p>Add the following menu items:<\/p>\n<ol>\n<li>\n<p>Item name: <strong>PageView<\/strong>, Value: <strong>PageView<\/strong><\/p>\n<\/li>\n<li>\n<p>Item name: <strong>Lead<\/strong>, Value: <strong>Lead<\/strong><\/p>\n<\/li>\n<li>\n<p>Item name: <strong>CompleteRegistration<\/strong>, Value: <strong>CompleteRegistration<\/strong><\/p>\n<\/li>\n<li>\n<p>Item name: <strong>Custom<\/strong>, Value: <strong>Custom<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>Click <strong>Add field<\/strong> under <strong>Nested fields<\/strong>, and choose a <strong>Text Input<\/strong> field. Name the field <code>customEventName<\/code>, and choose the <strong>Display name<\/strong> and <strong>Enabling conditions<\/strong> field configurations for it.<\/p>\n<ol>\n<li>\n<p><strong>Display name<\/strong>: Custom Event Name<\/p>\n<\/li>\n<li>\n<p><strong>Enabling conditions<\/strong>: <code>eventName<\/code> equals <code>Custom<\/code><\/p>\n<\/li>\n<\/ol>\n<div style=\"aspect-ratio: 1812 \/ 668;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/enabling-conditions.jpg\" title=\"enabling conditions\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"668\" width=\"1812\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/enabling-conditions.jpg#ZgotmplZ\" alt=\"enabling conditions\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The enabling condition ensures the Custom Event Name is only shown in case \u201cCustom\u201d is chosen from the drop-down menu. Cool, huh?<\/p>\n<h4 id=\"field-3-group-named-objectproperties\">Field 3: Group named <code>objectProperties<\/code><\/h4>\n<div style=\"aspect-ratio: 1902 \/ 742;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/group-field.jpg\" title=\"Group field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"742\" width=\"1902\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/group-field.jpg#ZgotmplZ\" alt=\"Group field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The default field configurations should be all you need for this Group field.<\/p>\n<ol>\n<li>\n<p><strong>Group style<\/strong>: Collapsible section &#8211; Collapsed<\/p>\n<\/li>\n<li>\n<p><strong>Display name<\/strong>: Object Properties<\/p>\n<\/li>\n<li>\n<p><strong>Nested fields<\/strong>: (see below)<\/p>\n<\/li>\n<\/ol>\n<p>Click <strong>Add field<\/strong> under <strong>Nested fields<\/strong>, and choose a <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#simple-table\"><strong>Simple Table<\/strong><\/a> field. Name the field <code>propertyList<\/code> and make sure the <strong>\u201cNew row\u201d button text<\/strong> field configuration is toggled on.<\/p>\n<p>Add <strong>two<\/strong> columns to the table. Both should be <strong>Text field<\/strong> columns.<\/p>\n<p>The first column should have the following settings:<\/p>\n<ol>\n<li>\n<p><strong>Column name<\/strong>: <code>Property Name<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Internal name<\/strong>: <code>name<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Require column values to be unique<\/strong>: Checked (this option becomes available when you choose to show <strong>Advanced Settings<\/strong> for this column)<\/p>\n<\/li>\n<\/ol>\n<p>The second column should have the following settings:<\/p>\n<ol>\n<li>\n<p><strong>Column name<\/strong>: <code>Property Value<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Internal name<\/strong>: <code>value<\/code><\/p>\n<\/li>\n<\/ol>\n<div style=\"aspect-ratio: 1628 \/ 770;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/propertylist-field.jpg\" title=\"Property List field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"770\" width=\"1628\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/propertylist-field.jpg#ZgotmplZ\" alt=\"Property List field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Finally, set the <strong>\u201cNew row\u201d button text<\/strong> option to <code>Add property<\/code>, and leave the <strong>Display name<\/strong> setting blank.<\/p>\n<h4 id=\"field-4-group-named-moresettings\">Field 4: Group named <code>moreSettings<\/code><\/h4>\n<div style=\"aspect-ratio: 1892 \/ 1076;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/moresettings-field.jpg\" title=\"More settings field\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1076\" width=\"1892\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/moresettings-field.jpg#ZgotmplZ\" alt=\"More settings field\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Set the following settings for the group:<\/p>\n<ol>\n<li>\n<p><strong>Group style<\/strong>: Collapsible section &#8211; Collapsed<\/p>\n<\/li>\n<li>\n<p><strong>Display name<\/strong>: <code>More Settings<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Nested fields<\/strong>: (see below)<\/p>\n<\/li>\n<\/ol>\n<p>Click <strong>Add field<\/strong> under <strong>Nested fields<\/strong>, and choose a <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#checkbox\"><strong>Checkbox<\/strong><\/a> field. Name the field <code>disableAutoConfig<\/code> and make sure the <strong>Help text<\/strong> field configuration is toggled on.<\/p>\n<ol>\n<li>\n<p><strong>Checkbox text<\/strong>: <code>Disable Automatic Configuration<\/code><\/p>\n<\/li>\n<li>\n<p><strong>Help text<\/strong>: Facebook collects some metadata (e.g. structured data) and user interactions (e.g. clicks) automatically. Check this box to disable this automatic configuration of the pixel.<\/p>\n<\/li>\n<\/ol>\n<h3 id=\"step-3-edit-code\">Step 3: Edit code<\/h3>\n<p>Step on over to the <strong>Code editor<\/strong> tab, and replace the contents with the following JavaScript:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">const<\/span> createQueue = require(<span style=\"color:#a50\">'createQueue'<\/span>);\n<span style=\"color:#00a\">const<\/span> callInWindow = require(<span style=\"color:#a50\">'callInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> aliasInWindow = require(<span style=\"color:#a50\">'aliasInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> copyFromWindow = require(<span style=\"color:#a50\">'copyFromWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> setInWindow = require(<span style=\"color:#a50\">'setInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> injectScript = require(<span style=\"color:#a50\">'injectScript'<\/span>);\n<span style=\"color:#00a\">const<\/span> makeTableMap = require(<span style=\"color:#a50\">'makeTableMap'<\/span>);\n\n<span style=\"color:#00a\">const<\/span> initIds = copyFromWindow(<span style=\"color:#a50\">'_fbq_gtm_ids'<\/span>) || [];\n<span style=\"color:#00a\">const<\/span> pixelIds = data.pixelId;\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Utility function to use either fbq.queue[]\n<\/span><span style=\"color:#aaa;font-style:italic\">\/\/ (if the FB SDK hasn't loaded yet), or fbq.callMethod()\n<\/span><span style=\"color:#aaa;font-style:italic\">\/\/ if the SDK has loaded.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">const<\/span> getFbq = () =&gt; {\n  <span style=\"color:#aaa;font-style:italic\">\/\/ Return the existing 'fbq' global method if available\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  <span style=\"color:#00a\">const<\/span> fbq = copyFromWindow(<span style=\"color:#a50\">'fbq'<\/span>);\n  <span style=\"color:#00a\">if<\/span> (fbq) {\n    <span style=\"color:#00a\">return<\/span> fbq;\n  }\n  \n  <span style=\"color:#aaa;font-style:italic\">\/\/ Initialize the 'fbq' global method to either use\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  <span style=\"color:#aaa;font-style:italic\">\/\/ fbq.callMethod or fbq.queue)\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  setInWindow(<span style=\"color:#a50\">'fbq'<\/span>, <span style=\"color:#00a\">function<\/span>() {    \n    <span style=\"color:#00a\">const<\/span> callMethod = copyFromWindow(<span style=\"color:#a50\">'fbq.callMethod.apply'<\/span>);\n    <span style=\"color:#00a\">if<\/span> (callMethod) {           \n      callInWindow(<span style=\"color:#a50\">'fbq.callMethod.apply'<\/span>, <span style=\"color:#00a\">null<\/span>, arguments); \n    } <span style=\"color:#00a\">else<\/span> {       \n      callInWindow(<span style=\"color:#a50\">'fbq.queue.push'<\/span>, arguments);\n    }\n  });\n  aliasInWindow(<span style=\"color:#a50\">'_fbq'<\/span>, <span style=\"color:#a50\">'fbq'<\/span>);\n  \n  <span style=\"color:#aaa;font-style:italic\">\/\/ Create the fbq.queue\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  createQueue(<span style=\"color:#a50\">'fbq.queue'<\/span>);\n    \n  <span style=\"color:#aaa;font-style:italic\">\/\/ Return the global 'fbq' method, created above\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  <span style=\"color:#00a\">return<\/span> copyFromWindow(<span style=\"color:#a50\">'fbq'<\/span>);\n};\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Get reference to the global method\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">const<\/span> fbq = getFbq();\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Build the fbq() command arguments\n<\/span><span style=\"color:#aaa;font-style:italic\"\/><span style=\"color:#00a\">const<\/span> props = data.propertyList ? makeTableMap(data.propertyList, <span style=\"color:#a50\">'name'<\/span>, <span style=\"color:#a50\">'value'<\/span>) : {};\n<span style=\"color:#00a\">const<\/span> command = data.eventName !== <span style=\"color:#a50\">'Custom'<\/span> ? <span style=\"color:#a50\">'trackSingle'<\/span> : <span style=\"color:#a50\">'trackSingleCustom'<\/span>;\n<span style=\"color:#00a\">const<\/span> eventName = data.eventName !== <span style=\"color:#a50\">'Custom'<\/span> ? data.eventName : data.customEventName;\n\n<span style=\"color:#aaa;font-style:italic\">\/\/ Handle multiple, comma-separated pixel IDs,\n<\/span><span style=\"color:#aaa;font-style:italic\">\/\/ and initialize each ID if not done already.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>pixelIds.split(<span style=\"color:#a50\">','<\/span>).forEach(pixelId =&gt; {\n  <span style=\"color:#00a\">if<\/span> (initIds.indexOf(pixelId) === -<span style=\"color:#099\">1<\/span>) {\n    \n    <span style=\"color:#aaa;font-style:italic\">\/\/ If the user has chosen to disable automatic configuration\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#00a\">if<\/span> (data.disableAutoConfig) {\n      fbq(<span style=\"color:#a50\">'set'<\/span>, <span style=\"color:#a50\">'autoConfig'<\/span>, <span style=\"color:#00a\">false<\/span>, pixelId);\n    }\n\n    <span style=\"color:#aaa;font-style:italic\">\/\/ Initialize pixel and store in global array\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    fbq(<span style=\"color:#a50\">'init'<\/span>, pixelId);\n    initIds.push(pixelId);\n    setInWindow(<span style=\"color:#a50\">'_fbq_gtm_ids'<\/span>, initIds, <span style=\"color:#00a\">true<\/span>);\n    \n  }\n  \n  <span style=\"color:#aaa;font-style:italic\">\/\/ Call the fbq() method with the parameters defined earlier\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  fbq(command, pixelId, eventName, props);\n});\n\ninjectScript(<span style=\"color:#a50\">'https:\/\/connect.facebook.net\/en_US\/fbevents.js'<\/span>, data.gtmOnSuccess, data.gtmOnFailure, <span style=\"color:#a50\">'fbPixel'<\/span>);\n<\/code><\/pre>\n<\/div>\n<p>At this point, it\u2019s a good idea to take a short breather.<\/p>\n<p>If you take a close look at the code, you\u2019ll see that it\u2019s far more complex than what the Facebook pixel snippet is. The reason for this is the <a href=\"https:\/\/www.simoahava.com\/analytics\/custom-templates-guide-for-google-tag-manager\/#sandboxed-javascript\">sandboxed JavaScript<\/a> that custom templates use. For example, the Facebook snippet creates the global <code>fbq()<\/code> method with something like:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#0aa\">window<\/span>.fbq = <span style=\"color:#00a\">function<\/span>() {\n  <span style=\"color:#0aa\">window<\/span>.fbq.callMethod ? \n    <span style=\"color:#0aa\">window<\/span>.fbq.callMethod.apply(<span style=\"color:#0aa\">window<\/span>.fbq, arguments) :\n    <span style=\"color:#0aa\">window<\/span>.fbq.queue.push(arguments);\n}\n<\/code><\/pre>\n<\/div>\n<p>It\u2019s a very simple piece of code, which simply passes the arguments you provide to <code>fbq()<\/code> (e.g. <code>'track', 'PageView'<\/code>) to one of two places, depending on whether the SDK has loaded yet or not.<\/p>\n<p>To do this in a custom template is far more complicated. You can\u2019t just set a global variable, you need to use an API for that. You can\u2019t just check if a global method exists, you need an API for that. And you can\u2019t just create the <code>queue<\/code> property for the <code>fbq()<\/code> method, you need an API for that.<\/p>\n<p>So, let\u2019s go over block by block to understand what the code does.<\/p>\n<h4 id=\"initialize-the-necessary-apis\">Initialize the necessary APIs<\/h4>\n<p>This script needs a handful of APIs, which are initialized with the <code>require()<\/code> API:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">const<\/span> createQueue = require(<span style=\"color:#a50\">'createQueue'<\/span>);\n<span style=\"color:#00a\">const<\/span> callInWindow = require(<span style=\"color:#a50\">'callInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> aliasInWindow = require(<span style=\"color:#a50\">'aliasInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> copyFromWindow = require(<span style=\"color:#a50\">'copyFromWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> setInWindow = require(<span style=\"color:#a50\">'setInWindow'<\/span>);\n<span style=\"color:#00a\">const<\/span> injectScript = require(<span style=\"color:#a50\">'injectScript'<\/span>);\n<span style=\"color:#00a\">const<\/span> makeTableMap = require(<span style=\"color:#a50\">'makeTableMap'<\/span>);\n<\/code><\/pre>\n<\/div>\n<p>I\u2019ll explain how they function when we encounter them in the code.<\/p>\n<h4 id=\"fetch-list-of-initialized-ids\">Fetch list of initialized IDs<\/h4>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">const<\/span> initIds = copyFromWindow(<span style=\"color:#a50\">'_fbq_gtm_ids'<\/span>) || [];\n<span style=\"color:#00a\">const<\/span> pixelIds = data.pixelId;\n<\/code><\/pre>\n<\/div>\n<p>Here we fetch the list of initialized IDs (stored in a custom <code>_fbq_gtm_ids<\/code> global array), and we also pull in the value, input by the user, of the <code>pixelId<\/code> field from the template itself.<\/p>\n<h4 id=\"utility-to-fetch-the-proper-global-fbq-method\">Utility to fetch the proper global <code>fbq<\/code> method<\/h4>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">const<\/span> getFbq = () =&gt; {\n  <span style=\"color:#aaa;font-style:italic\">\/\/ Return the existing 'fbq' global method if available\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>  <span style=\"color:#00a\">const<\/span> fbq = copyFromWindow(<span style=\"color:#a50\">'fbq'<\/span>);\n  <span style=\"color:#00a\">if<\/span> (fbq) {\n    <span style=\"color:#00a\">return<\/span> fbq;\n  }\n  ...\n<\/code><\/pre>\n<\/div>\n<blockquote>\n<p>NOTE! The <strong>arrow function<\/strong> is a feature of <a href=\"https:\/\/www.w3schools.com\/js\/js_es6.asp\">ES6<\/a> supported by Custom Templates. <code>const getFbq = () =&gt; {<\/code> translates to <code>var getFbq = function() {<\/code> in the older flavor of JavaScript.<\/p>\n<\/blockquote>\n<p>The purpose of <code>getFbq<\/code> is to return a representation of the global <code>fbq<\/code> method, which passes the arguments to the correct place, similar to how the regular Facebook snippet works.<\/p>\n<p>The first lines check if <code>fbq<\/code> has already been created globally, and returns the global method in that case.<\/p>\n<p>In case the global method does <strong>not<\/strong> exist, it needs to be created.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\">  ...\n  setInWindow(<span style=\"color:#a50\">'fbq'<\/span>, <span style=\"color:#00a\">function<\/span>() {    \n    <span style=\"color:#00a\">const<\/span> callMethod = copyFromWindow(<span style=\"color:#a50\">'fbq.callMethod.apply'<\/span>);\n    <span style=\"color:#00a\">if<\/span> (callMethod) {           \n      callInWindow(<span style=\"color:#a50\">'fbq.callMethod.apply'<\/span>, <span style=\"color:#00a\">null<\/span>, arguments); \n    } <span style=\"color:#00a\">else<\/span> {       \n      callInWindow(<span style=\"color:#a50\">'fbq.queue.push'<\/span>, arguments);\n    }\n  });\n  aliasInWindow(<span style=\"color:#a50\">'_fbq'<\/span>, <span style=\"color:#a50\">'fbq'<\/span>);\n  ...\n<\/code><\/pre>\n<\/div>\n<p>Here, the global <code>fbq<\/code> method is initialized as a new function. This function first checks if the <code>fbq.callMethod<\/code> method already exists (which means the FB SDK has loaded), and if it does, it passes the arguments sent to the <code>fbq<\/code> method (e.g. <code>'track', 'PageView'<\/code>) to this built-in method.<\/p>\n<p>If the <code>callMethod<\/code> method has <strong>not<\/strong> been created yet, then the method passes its arguments to <code>fbq.queue<\/code> as an array push. The queue is basically a waiting list for pixel request, queued up for the Facebook SDK as it loads over the network. Once the SDK has loaded, it processes the messages in this queue and dispatches them to Facebook.<\/p>\n<p>The last line makes an alias of the <code>fbq<\/code> method in another global variable, <code>_fbq<\/code>. I\u2019m not certain why this is necessary, but it is what the Facebook snippet does as well.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\">  ...\n  createQueue(<span style=\"color:#a50\">'fbq.queue'<\/span>);\n  \n  <span style=\"color:#00a\">return<\/span> copyFromWindow(<span style=\"color:#a50\">'fbq'<\/span>);\n};\n<\/code><\/pre>\n<\/div>\n<p>The last lines of the <code>setInWindow<\/code> API call create the <code>fbq.queue<\/code> global array, before finally returning the current content of the global <code>fbq<\/code> variable, which is the function you created above.<\/p>\n<h4 id=\"prepare-the-fbq-command\">Prepare the <code>fbq<\/code> command<\/h4>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">const<\/span> fbq = getFbq();\n\n<span style=\"color:#00a\">const<\/span> props = data.propertyList ? makeTableMap(data.propertyList, <span style=\"color:#a50\">'name'<\/span>, <span style=\"color:#a50\">'value'<\/span>) : {};\n<span style=\"color:#00a\">const<\/span> command = data.eventName !== <span style=\"color:#a50\">'Custom'<\/span> ? <span style=\"color:#a50\">'trackSingle'<\/span> : <span style=\"color:#a50\">'trackSingleCustom'<\/span>;\n<span style=\"color:#00a\">const<\/span> eventName = data.eventName !== <span style=\"color:#a50\">'Custom'<\/span> ? data.eventName : data.customEventName;\n<\/code><\/pre>\n<\/div>\n<p>These lines first fetch the latest representation of the <code>fbq<\/code> global method by invoking the <code>getFbq<\/code> function you <em>just<\/em> created.<\/p>\n<p>Next, the contents of the <code>fbq<\/code> command are built. The <code>makeTableMap<\/code> API takes your <code>propertyList<\/code> Simple Table field, and converts each row to a key-value pair, where the key is the first column value (e.g. <code>content_ids<\/code>), and the value is the second column value (e.g. <code>123456<\/code>). It\u2019s a really handy API for converting the template table format into what many JavaScript libraries expect.<\/p>\n<p>The <code>command<\/code> variable depends on whether you\u2019re using a standard event (e.g. PageView or Lead), in which case it is set to <code>trackSingle<\/code>, or whether you\u2019re using the Custom event, in which case it\u2019s set to <code>trackSingleCustom<\/code>.<\/p>\n<p>The <code>eventName<\/code> takes either the value of the drop-down menu selection if a standard event is selected, or the value of the <code>customEventName<\/code> text input field if a Custom event is selected.<\/p>\n<h4 id=\"cycle-through-all-pixel-ids-defined-in-tag-and-dispatch-the-commands\">Cycle through all Pixel IDs defined in tag, and dispatch the commands<\/h4>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\">pixelIds.split(<span style=\"color:#a50\">','<\/span>).forEach(pixelId =&gt; {\n  <span style=\"color:#00a\">if<\/span> (initIds.indexOf(pixelId) === -<span style=\"color:#099\">1<\/span>) {\n    <span style=\"color:#00a\">if<\/span> (data.disableAutoConfig) {\n      fbq(<span style=\"color:#a50\">'set'<\/span>, <span style=\"color:#a50\">'autoConfig'<\/span>, <span style=\"color:#00a\">false<\/span>, pixelId);\n    }\n    fbq(<span style=\"color:#a50\">'init'<\/span>, pixelId);\n    initIds.push(pixelId);\n    setInWindow(<span style=\"color:#a50\">'_fbq_gtm_ids'<\/span>, initIds, <span style=\"color:#00a\">true<\/span>);\n  }\n  \n  fbq(command, pixelId, eventName, props);\n});\n<\/code><\/pre>\n<\/div>\n<p>The whole command process is wrapped in an iterator, which loops through all the Pixel IDs the user has added to the tag. The commands are run identically for every single Pixel ID in the tag.<\/p>\n<p>First, the code checks if the Pixel ID has already been initialized by looking at the contents of the <code>initIds<\/code> array you created at the very beginning of the code. You don\u2019t want to initialize any Pixel ID more than once, or you\u2019ll risk running into problems with Facebook\u2019s SDK.<\/p>\n<p>If the pixel hasn\u2019t been initialized, then first the <code>autoConfig<\/code> parameter is set to <code>false<\/code>, if the user has checked the respective checkbox in the template.<\/p>\n<p>Next, the <code>fbq('init', pixelId)<\/code> command is run, after which the Pixel ID is pushed into the array of initialized pixels.<\/p>\n<p>Finally, the <code>fbq()<\/code> command is run with the parameters you created previously.<\/p>\n<h4 id=\"load-the-facebook-sdk\">Load the Facebook SDK<\/h4>\n<p>The very last line in the code editor loads the Facebook SDK, and signals either <code>data.gtmOnSuccess()<\/code> or <code>data.gtmOnFailure<\/code>, depending on whether the SDK load was successful or not.<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\">injectScript(<span style=\"color:#a50\">'https:\/\/connect.facebook.net\/en_US\/fbevents.js'<\/span>, data.gtmOnSuccess, data.gtmOnFailure, <span style=\"color:#a50\">'fbPixel'<\/span>);\n<\/code><\/pre>\n<\/div>\n<h3 id=\"step-4-permissions\">Step 4: Permissions<\/h3>\n<p>Because you use all these APIs and mess so much with the global namespace, you\u2019ll need to add some permissions if you want the template code to run.<\/p>\n<div style=\"aspect-ratio: 1914 \/ 1302;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-permissions.jpg\" title=\"Facebook permissions\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1302\" width=\"1914\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-permissions.jpg#ZgotmplZ\" alt=\"Facebook permissions\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>As you can see, every single global variable you interact with, either directly (via <code>copyFromWindow<\/code>, <code>callInWindow<\/code>, etc.) or indirectly (via <code>aliasFromWindow<\/code>) must be specified in the Permissions list.<\/p>\n<p>Similarly, the script injection of the SDK itself must be allowed using the appropriate permission.<\/p>\n<h3 id=\"test-it\">Test it!<\/h3>\n<p>To test it, <strong>save<\/strong> the template, then browse to your container\u2019s tags, and create a new tag. You should see the Facebook Pixel in the tag menu.<\/p>\n<div style=\"aspect-ratio: 2082 \/ 802;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/choose-facebook-pixel.jpg\" title=\"Choose new pixel\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"802\" width=\"2082\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/choose-facebook-pixel.jpg#ZgotmplZ\" alt=\"Choose new pixel\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Next, fill in the fields. Try a couple of different things, such as passing various object properties, using custom events, and adding more than one Pixel ID.<\/p>\n<div style=\"aspect-ratio: 1778 \/ 1224;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/test-facebook-pixel.jpg\" title=\"test pixel\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1224\" width=\"1778\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/test-facebook-pixel.jpg#ZgotmplZ\" alt=\"test pixel\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Try also creating more than one tag with the same Pixel ID, to make sure the initialization is done just once per ID.<\/p>\n<p>Using GTM Preview mode and <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/facebook-pixel-helper\/fdgfkebogiimcoedlicjlajpkdmockpc?hl=en\">Facebook\u2019s Pixel Helper<\/a>, you should be able to verify that everything is working as it should.<\/p>\n<div style=\"aspect-ratio: 1432 \/ 1200;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-pixel-helper.jpg\" title=\"Facebook pixel helper\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"1200\" width=\"1432\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2019\/05\/facebook-pixel-helper.jpg#ZgotmplZ\" alt=\"Facebook pixel helper\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h2 id=\"final-thoughts\">Final thoughts<\/h2>\n<p>I hope this article has helped demystify custom templates.<\/p>\n<p>As you can see, working with the sandboxed JavaScript isn\u2019t just a question of copy-pasting some original code and rewriting some method calls. It calls for a different approach completely, especially when working with global variables.<\/p>\n<p>There are some things I think custom templates should do to improve flexibility. For example, the function wrapper that GTM automatically adds whenever you create a global function is problematic, since there are use cases where you might want to be able to add properties to the global function itself. In its current format, custom templates do not permit this, so you need to use an API like <code>createQueue<\/code> to establish <code>fbq.queue<\/code> as an array.<\/p>\n<p>It would be better if I could just run something like <code>setInWindow('fbq.queue', [])<\/code>, but right now, <code>setInWindow<\/code> only allows you to set the variable and not its individual properties.<\/p>\n<p>Other than that, the benefit of using this over a Custom HTML tag is huge: you\u2019re minimizing the risk of code errors due to operating through the template, and you don\u2019t need the problematic <code>unsafe-eval<\/code> directive in your <a href=\"https:\/\/www.simoahava.com\/analytics\/google-tag-manager-content-security-policy\/\">Content Security Policy<\/a>.<\/p>\n<p>Thanks for reading, and perhaps watching! Let me know in the comments if you have questions about how this whole thing works.<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>After the recent release of Custom Templates for Google Tag Manager, my mind has been occupied by very little else. However, I have a nagging feeling that due to how involved the feature set is, there\u2019s still a lot of demystifying that needs to take place before templates are fully embraced by the GTM user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":99141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[7957,834,15100,14492,24001,1791,4196],"dealstore":[],"offerexpiration":[],"class_list":["post-99140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-create","tag-custom","tag-facebook","tag-gtmtips","tag-pixel","tag-tag","tag-template"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=99140\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"After the recent release of Custom Templates for Google Tag Manager, my mind has been occupied by very little else. However, I have a nagging feeling that due to how involved the feature set is, there\u2019s still a lot of demystifying that needs to take place before templates are fully embraced by the GTM user [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=99140\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-20T09:25:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=99140#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"#GTMTips: Create Facebook Pixel Custom Tag Template\",\"datePublished\":\"2025-02-20T09:25:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140\"},\"wordCount\":2056,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg\",\"keywords\":[\"create\",\"Custom\",\"Facebook\",\"GTMTips\",\"Pixel\",\"TAG\",\"Template\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=99140#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=99140\",\"url\":\"https:\/\/fivemor.com\/?p=99140\",\"name\":\"#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg\",\"datePublished\":\"2025-02-20T09:25:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=99140#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=99140\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=99140#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg\",\"width\":960,\"height\":540},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=99140#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"#GTMTips: Create Facebook Pixel Custom Tag Template\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=99140","og_locale":"en_US","og_type":"article","og_title":"#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network","og_description":"After the recent release of Custom Templates for Google Tag Manager, my mind has been occupied by very little else. However, I have a nagging feeling that due to how involved the feature set is, there\u2019s still a lot of demystifying that needs to take place before templates are fully embraced by the GTM user [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=99140","og_site_name":"Som2ny Network","article_published_time":"2025-02-20T09:25:03+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=99140#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=99140"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"#GTMTips: Create Facebook Pixel Custom Tag Template","datePublished":"2025-02-20T09:25:03+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=99140"},"wordCount":2056,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=99140#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg","keywords":["create","Custom","Facebook","GTMTips","Pixel","TAG","Template"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=99140#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=99140","url":"https:\/\/fivemor.com\/?p=99140","name":"#GTMTips: Create Facebook Pixel Custom Tag Template - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=99140#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=99140#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg","datePublished":"2025-02-20T09:25:03+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=99140#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=99140"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=99140#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/create-facebook-pixel-template.jpg","width":960,"height":540},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=99140#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"#GTMTips: Create Facebook Pixel Custom Tag Template"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/99140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99140"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/99140\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/99141"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99140"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=99140"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=99140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}