8

I can't seem to get Segment to work despite following these instructions: https://segment.com/docs/platforms/chrome-extension/

When I run analytics.track, I don't see any network requests for the tracking pixels but I don't see any error either. The analytics object exists, but it doesn't seem to do anything.

It's important to note here that I'd like to run Segment from the context of the page. My extension injects new DOM elements and CSS styles into the webpage and I want to track the user's interactions with these elements. So Segment is not running in the context of the extension at all. It's injected into the page's head as a script.

user438293456
  • 596
  • 3
  • 6
  • 19

2 Answers2

4

Steven here from Segment. We recommend loading analytics.js on a background page, so as not to interfere with the analytics tools that have already been loaded onto the page. In either case, you would do the following:

  1. Create a file called snippet.js with the analytics.js snippet inside it.

  2. Inject the file onto the current page:

    chrome.tabs.executeScript(null, {file: 'snippet.js'});

Community
  • 1
  • 1
  • 1
    This library seems to be deprecated now. What do you suggest to use in chrome-extensions now? The HTTP API: https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/ – dhruv2204 May 13 '21 at 19:42
  • 1
    I have the same question. I wish there were a way to tell Segment. Instead of pulling down files from the cloud, use the local ones I have. – Samuel Mburu Jun 10 '21 at 14:04
  • I would be interested in an up-to-date solution as well. – p6l-richard Nov 13 '21 at 13:28
0

According to the following link, segment how to do this

In 2018 we fully deprecated and stopped supporting the following Segment source “plugins”:

You can now refer use their npm package for this. Here is the link on the steps

Gangula
  • 5,193
  • 4
  • 30
  • 59