Giter VIP home page Giter VIP logo

svelte-facebook-pixel's Issues

Init function does not work with SvelteKit

The init function as it's currently implemented does not work with SvelteKit. If you have preloading enabled in SvelteKit, then javascript is loaded in link tags instead of script tags, so the follow function fails.

export function init () {
    const fn = 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 = version
      n.queue = []
      t = b.createElement(e)
      t.async = !0
      t.src = v
      s = b.getElementsByTagName(e)[0]
      s.parentNode.insertBefore(t, s)
    }

    fn(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js')
    callback()
  }

I made it work for my purposes by changing the line to s = b.getElementsByTagName('link')[0] but that is obviously not a generalized solution.

SvelteKit TS / Support

Hello

I tried to use this package with Svelte Kit with TS.

are there plans to add support to it ?

The errors I got.

  1. There was no default export, solved it with { }
  2. There are no definition files, kind of did a work around on it.
  3. After following the instruction I was getting that fb was not a function, noticed there is an export of fb, I tried to call it but the pixel didnt fire up.

how to track a purchase?

fbq("Purchase", { currency, value });

getting this warning

fbq('Purchase', ...);" is not a valid fbq command.

tracking conversions?

ANyone know what that means? I was asked to add facebook page views tracking and conversion tracking on order success page.

error

Uncaught (in promise) TypeError: _fbq is not a function

FacebookPixel.svelte:73 Uncaught (in promise) TypeError: _fbq is not a function
    at query (FacebookPixel.svelte:73)
    at FacebookPixel.track (FacebookPixel.svelte:68)
    at _layout.svelte:14
    at run (index.mjs:18)
    at Array.map (<anonymous>)
    at index.mjs:1372
    at flush (index.mjs:708)
    at init (index.mjs:1458)
    at new App (App.svelte:17)
    at render (app.mjs:288)






<script>
  import { goto, stores } from "@sapper/app";
  import { onMount } from "svelte";
  import FacebookPixel from "@beyonk/svelte-facebook-pixel";
  import Navbar from "../components/Navbar.svelte";
  import Footer from "../components/Footer.svelte";
  import Banner from "../components/Banner.svelte";

  const { page } = stores();
  export let segment;
  let fb;

  onMount(() => {
    fb.track("PageView");
  });
</script>

<style>
  main {
    position: relative;
    background-color: #0f1217;
    padding: 0;
    margin: 0 auto;
    box-sizing: border-box;
    color: #fff;
  }

  .mobile-buy-droids {
    display: none;
  }

  @media only screen and (max-width: 768px) {
    .mobile-buy-droids {
      display: flex;
      justify-content: flex-end;
      position: fixed;
      bottom: 0%;
      width: 100%;
      opacity: 1;
      z-index: 2;
    }
  }
</style>

<Navbar {segment} />
<Banner />
<main>
  {#if $page.path !== '/buy'}
    <section class="mobile-buy-droids">
      <a href="buy">
        <img src="/images/droids-buy-now.png" alt="Buy Droids" />
      </a>
    </section>
  {/if}
  <slot />
</main>

<Footer {segment} />
<FacebookPixel bind:this={fb} id={FACEBOOK_TRACKING_ID} />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.