benjaminhoffman / gatsby-plugin-segment-js

Gatsby plugin for segment.com's analytic.js snippet
https://www.npmjs.com/package/gatsby-plugin-segment-js
MIT License
40 stars 28 forks source link

Not receiving tracking events #11

Closed mic-css closed 5 years ago

mic-css commented 5 years ago

Hi, I'm not receiving any tracking events.

I have no problem tracking with the deprecated package (gatsby-plugin-segment) but after uninstalling it and installing this package no tracking events come through.

Any help would be much appreciated.

gatsby-config.js below:

module.exports = {
  siteMetadata: {
    // ...
  },
  plugins: [
    // ...
    {
      resolve: `gatsby-plugin-segment-js`,
      options: {
        prodKey: `<PROD_WRITE_KEY>`,
        devKey: `<OTHER_WRITE_KEY>`,
      },
    },
  ],
}

Working correctly with deprecated library, for reference:

module.exports = {
  siteMetadata: {
    // ...
  },
  plugins: [
    // ...
    {
      resolve: `gatsby-plugin-segment`,
      options: {
        writeKey: `<PROD_WRITE_KEY>`,
      },
    },
  ],
}
benjaminhoffman commented 5 years ago

can you copy/paste the component you are trying to invoke the track method in? I just created a super simple example repo where you can see how I am doing it: https://github.com/benjaminhoffman/gatsby-plugin-segment-js/blob/master/example/src/pages/index.js#L12

In addition to sharing the code / component of where you invoke Segment, can you also help answer whether that area of the code is getting it. If it is, check your Network tab of your browser dev tools... do you see a Segment track call being made? If so, is it returning a 200 status code? If so, then you're sure the event isn't making it through?

Also, be sure to upgrade to the latest version of this package... I just bumped the Segment version to 4.1.0! 🌮

mic-css commented 5 years ago

@benjaminhoffman thanks for the reply and example.

I'm not explicitly firing any tracking events - the old library automatically registered page views with Segment. Has this behaviour changes in the new one?

mic-css commented 5 years ago

Apologies, I hadn't realised that trackPage defaults to false! Thanks for the help anyway.