- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello guys, I want to add Facebook pixel script in header tag. In which file or path where i got the header file. Can anyone help me ???
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to add only script you can add it directly from Admin panel.
Go To Content tab from left side,
Click on Design -> Configuration
Now edit your theme and click on HTML Head section,
add your script inside,
Scripts and Style Sheets field and save.
Clear cache.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: insert Facebook Pixel script in header tag
You can get header.phtml file from
vendor/magento/module-theme/view/frontend/templates/html/header.phtml
path.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want to add only script you can add it directly from Admin panel.
Go To Content tab from left side,
Click on Design -> Configuration
Now edit your theme and click on HTML Head section,
add your script inside,
Scripts and Style Sheets field and save.
Clear cache.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: insert Facebook Pixel script in header tag
I want add Facebook pixel code in this page..this is my code
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '290769584684XXX');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=290769584684291&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
and this is my header.phtml file
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** * @var \Magento\Theme\Block\Html\Header $block */ $welcomeMessage = $block->getWelcome(); ?> <?php switch ($block->getShowPart()): case 'welcome': ?> <li class="greet welcome" data-bind="scope: 'customer'"> <!-- ko if: customer().fullname --> <span data-bind="text: new String('<?php echo $block->escapeHtml(__('Welcome, %1!', '%1'));?>').replace('%1', customer().firstname)"> </span> <!-- /ko --> <!-- ko ifnot: customer().fullname --> <span data-bind="html:'<?=$block->escapeHtml($welcomeMessage) ?>'"></span> <!-- /ko --> </li> <script type="text/x-magento-init"> { "*": { "Magento_Ui/js/core/app": { "components": { "customer": { "component": "Magento_Customer/js/view/customer" } } } } } </script>
<?php break; ?>
<?php case 'other': ?>
<?php echo $block->getChildHtml(); ?>
<?php break; ?>
<?php endswitch; ?>
So, Tell me where i put this code in this header.phtml
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: insert Facebook Pixel script in header tag
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** * @var \Magento\Theme\Block\Html\Header $block */ $welcomeMessage = $block->getWelcome(); ?> <?php switch ($block->getShowPart()): case 'welcome': ?> <li class="greet welcome" data-bind="scope: 'customer'"> <!-- ko if: customer().fullname --> <span data-bind="text: new String('<?php echo $block->escapeHtml(__('Welcome, %1!', '%1'));?>').replace('%1', customer().firstname)"> </span> <!-- /ko --> <!-- ko ifnot: customer().fullname --> <span data-bind="html:'<?=$block->escapeHtml($welcomeMessage) ?>'"></span> <!-- /ko --> </li> <script type="text/x-magento-init"> { "*": { "Magento_Ui/js/core/app": { "components": { "customer": { "component": "Magento_Customer/js/view/customer" } } } } } </script> <?php break; ?> <?php case 'other': ?> <?php echo $block->getChildHtml(); ?> <?php break; ?> <?php endswitch; ?> <!-- Facebook Pixel Code --> <script> !function(f,b,e,v,n,t,s) {if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)}; if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b.getElementsByTagName(e)[0]; s.parentNode.insertBefore(t,s)}(window, document,'script', 'https://connect.facebook.net/en_US/fbevents.js'); fbq('init', '290769584684XXX'); fbq('track', 'PageView'); </script> <noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=290769584684291&ev=PageView&noscript=1" /></noscript> <!-- End Facebook Pixel Code -->
Magento 2 Blogs/Tutorial