Using IO segment in Chrome extension

I am unable to get Segment to work despite the following instructions: https://segment.com/docs/platforms/chrome-extension/

When I run analytics.track

, I don't see network requests for tracking pixels, but I don't see any error either. The object analytics

exists, but it does nothing.

It is important to note that I would like to run the segment from the context of the page. My extension is injecting new DOM elements and CSS styles into a web page and I want to track user interaction with those elements. So the segment is not executed at all in the extension context. It is injected into the page head

as script

.

+3


source to share


1 answer


Stephen is here from Segment . We recommend loading analytics.js on the original page to avoid interfering with analytics tools that have already been loaded on the page. In any case, you should do the following:



  • Create a snippet.js file with analytics.js snippet inside it.

  • Paste the file into the current page:

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

+2


source







All Articles