Skip to content

Instantly share code, notes, and snippets.

@tobsn
Created October 24, 2018 23:01
Show Gist options
  • Save tobsn/fbf50e6a16d075268e1eb403ad7bf8b4 to your computer and use it in GitHub Desktop.
Save tobsn/fbf50e6a16d075268e1eb403ad7bf8b4 to your computer and use it in GitHub Desktop.

Revisions

  1. tobsn created this gist Oct 24, 2018.
    34 changes: 34 additions & 0 deletions Tags > Facebook Checkout.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <script>
    (function(){

    var FBDATA = {
    sku: JSON.parse('{{CHECKOUT SKUS}}'), // cookie variable with array of SKUs (products on checkout page)
    ids: {{A - EDIT THIS - FACEBOOK PIXEL ID LIST}}, // Variable with Pixel IDs
    host: '{{Page Hostname}}'
    };

    for( var k in FBDATA.ids ) {
    if( k !== 'all' ) {
    if( FBDATA.host.indexOf( k ) === -1 ) {
    continue;
    }
    }
    if( FBDATA.ids[k].length < 1 ) {
    continue;
    }
    for( var kk in FBDATA.ids[k] ) {
    if( FBDATA.ids[k][kk].indexOf( ':' ) !== -1 ) {
    if( FBDATA.ids[k][kk].split(':')[0] !== '{{UTM_SOURCE}}' && '{{UTM_SOURCE}}' !== 'faceboook' ) {
    continue;
    }
    }
    fbq( 'init', FBDATA.ids[k][kk] );
    fbq( 'trackSingle', FBDATA.ids[k][kk], 'InitiateCheckout' );
    fbq( 'trackSingle', FBDATA.ids[k][kk], 'AddToCart', {
    content_type: 'product',
    content_ids: FBDATA.sku
    });
    }
    }
    })();
    </script>
    37 changes: 37 additions & 0 deletions Tags > Facebook Conversion.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <script>
    (function(){

    var FBDATA = {
    total: '{{PURCHASE TOTAL}}', // conversion purchase total
    currency: '{{CHECKOUT CURRENCY}}', // currency USD
    sku: '{{PURCHASE SKU}}', // products SKU string
    ids: {{A - EDIT THIS - FACEBOOK PIXEL ID LIST}}, // again static variable
    host: '{{Page Hostname}}'
    };

    for( var k in FBDATA.ids ) {
    if( k !== 'all' ) {
    if( FBDATA.host.indexOf( k ) === -1 ) {
    continue;
    }
    }
    if( FBDATA.ids[k].length < 1 ) {
    continue;
    }
    for( var kk in FBDATA.ids[k] ) {
    if( FBDATA.ids[k][kk].indexOf( ':' ) !== -1 ) {
    if( FBDATA.ids[k][kk].split(':')[0] !== '{{UTM_SOURCE}}' && '{{UTM_SOURCE}}' !== 'faceboook' ) {
    continue;
    }
    }
    fbq( 'init', FBDATA.ids[k][kk] );
    fbq( 'trackSingle', FBDATA.ids[k][kk], 'Purchase', {
    value: ((FBDATA.total!=='')?(FBDATA.total*1):100),
    currency: ((FBDATA.currency!=='')?FBDATA.currency:'USD'),
    content_type: 'product',
    content_id: FBDATA.sku
    });
    }
    }
    })();
    </script>
    29 changes: 29 additions & 0 deletions Tags > Facebook Pageview - Salespage.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <script>
    (function(){

    var FBDATA = {
    ids: {{A - EDIT THIS - FACEBOOK PIXEL ID LIST}},
    host: '{{Page Hostname}}'
    };

    for( var k in FBDATA.ids ) {
    if( k !== 'all' ) {
    if( FBDATA.host.indexOf( k ) === -1 ) {
    continue;
    }
    }
    if( FBDATA.ids[k].length < 1 ) {
    continue;
    }
    for( var kk in FBDATA.ids[k] ) {
    if( FBDATA.ids[k][kk].indexOf( ':' ) !== -1 ) {
    if( FBDATA.ids[k][kk].split(':')[0] !== '{{UTM_SOURCE}}' && '{{UTM_SOURCE}}' !== 'faceboook' ) {
    continue;
    }
    }
    fbq( 'init', FBDATA.ids[k][kk] );
    fbq( 'trackSingle', FBDATA.ids[k][kk], 'PageView' );
    }
    }
    })();
    </script>
    14 changes: 14 additions & 0 deletions Variables > Custom Javascript.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    function(){
    return {

    'all': [ // global not domain specific
    '123123123', // if no source is defined it defaults to facebook as utm_source
    'by-utm-source-name:123123123' // utm-source:pixel-id or just pixel-id
    ],

    'by-domain.com': [ // for if more than one domain is in play
    'some-affiliates-pixel:123123123'
    ],

    };
    }