GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Nullstack
  • What is Nullstack?
  • Documentation
  • Examples
  • Contributors
  • F.A.Q
  • Waifu
  • Português
  • Star
  • Leave a star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing nullstack.app — Facebook's Pixel - Nullstack

Facebook's Pixel

According to developers.facebook.com:

"The Facebook pixel is a snippet of JavaScript code that allows you to track visitor activity on your website."

You can take advantage of the context and custom events to create a component that dynamically sends Pixel events.

Facebook's Pixel can only be called after hydrate to ensure it is running in the client.

import Nullstack from 'nullstack';

class FacebookPixel extends Nullstack {

  async hydrate({page, id}) {
    ! 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', id);
    fbq('track', 'PageView');
    window.addEventListener(page.event, () => {
      fbq('init', id);
      fbq('track', 'PageView');
    })
  }
}

export default FacebookPixel;
import Nullstack from 'nullstack';
import FacebookPixel from './FacebookPixel';

class Application extends Nullstack {

  // ...

  render() {
    return (
      <main>
        <FacebookPixel id="REPLACE_WITH_YOUR_FACEBOOK_PIXEL_ID" />
      </main>
    )
  }


}

export default Application;

Using a Wrapper

Alternatively, you can install nullstack-facebook-pixel as a dependency:

npm install nullstack-facebook-pixel
import Nullstack from 'nullstack';
import FacebookPixel from 'nullstack-facebook-pixel';

class Application extends Nullstack {

  // ...

  render() {
    return (
      <main>
        <FacebookPixel id="REPLACE_WITH_YOUR_FACEBOOK_PIXEL_ID" />
      </main>
    )
  }


}

export default Application;
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.