Topic on Extension talk:HeadScript

Can I use the extension to place Fb's pixel on my wiki?

4
ZielonaMrowka (talkcontribs)

Hello! I wanted to add a Facebook's pixel to my wiki. It has to be placed in <head> of the website so I installed this extension and tried to add their script between <script></script> in LocalSettings.php. It does not work (I suppose that I'm placing the script in incorrect file :P) - probably "of course". The code after the </script> becomes grayed out (I use Notepad++) and colorizes back when I remove Fb's <script></script> body. The FB code looks as follows:

<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', 'I_probaby_shouldn't_share_the_number_that_was_here');
  fbq('track', 'PageView');
</script>

Is there a way to include it with this extension and no knowledge in php?

109.192.67.232 (talkcontribs)

Same Problem with Google AdWords Conversion Tracking Script

109.192.67.232 (talkcontribs)

The problem seems to be: If the script uses apostrophes, the extension doesn't work.

Seb35 (talkcontribs)

PHP has a special syntax to deal easily with this issue about apostrophes inside strings, it’s called Heredoc or Nowdoc syntax. I’ve added some instructions in the Configuration section. For your initial question, you can use it that way:

$wgHeadScriptCode = <<<'START_END_MARKER'
<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', 'I_probaby_shouldn't_share_the_number_that_was_here');
  fbq('track', 'PageView');
</script>
START_END_MARKER;
Reply to "Can I use the extension to place Fb's pixel on my wiki?"