npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@segment/analytics.js-integration

v3.3.4-alpha.5

Published

Base factory for analytics.js integrations

Downloads

90,949

Maintainers

yshkpryshkprpriyanshispriyanshisjbasiglio-segmentjbasiglio-segmentpraguptapraguptasbhodiwalsbhodiwalsahilsharma0709sahilsharma0709farhan0581farhan0581jkusa_segmentjkusa_segmentharksinghharksingharjunbhandagearjunbhandagey.yuy.yuslenin-twilioslenin-twilioskondamuriskondamurinithan-twilionithan-twiliopraveenugiripraveenugiribnakkinabnakkinahema-bahirwani-segmenthema-bahirwani-segmentsandhya16sandhya16nemery-segmentnemery-segmentighorelaighorelamansarimansaribhavanki-segmentbhavanki-segmentar7devar7devvaibhavnandavaibhavnandanikumarsegmentnikumarsegmentitsarijitrayitsarijitrayssunejassunejaazhaotwilioazhaotwilioldelossantosldelossantoscjo2cjo2achandrashekaranachandrashekaranaparna.singhalaparna.singhalynguyenynguyentimmyzsearcytimmyzsearcyigracheva-twilioigracheva-twilioyashnit-segmentyashnit-segmentnanotimmnanotimmsrivig21srivig21chenchensegmentcomchenchensegmentcomsanket.mishrasanket.mishralweimersegmentlweimersegmentrcheedhallarcheedhallajxin_twiliojxin_twilioodoren_segmentodoren_segmentaditi.raveeshaditi.raveeshdltnbrks-segmentdltnbrks-segmentsai-patanjalisai-patanjalihimanshuphhimanshuphalecjacobs-segmentalecjacobs-segmentsshaikh_segmentsshaikh_segmentjohn.lee1100john.lee1100dazu70dazu70brian.aguirrebrian.aguirrepooja.patilpooja.patilsegment_fansegment_fannlubchenconlubchencojsh-wujsh-wunithin-bennynithin-bennypoojasegmentpoojasegmentebru.odokebru.odokbannapplebannapplerodhilton_twiliorodhilton_twilioguthriesegmentguthriesegmentsrishti-nemasrishti-nemacdelaomartinezcdelaomartinezmiguelpdiaz8miguelpdiaz8sundareswar.jayakumarsundareswar.jayakumargbatragbatraspencerattickspencerattickakodankiryakodankirynanette.ranesnanette.ranesgsolis_segmentgsolis_segmentnitinpm432nitinpm432amigandhiamigandhisegmentseansegmentseanhmohanram_seghmohanram_segjrupasinghejrupasinghedevthaledevthalesmccoy-twiliosmccoy-twilioseg-leonelsanchesseg-leonelsanchesjibrangjibrangsethgrid_segmentsethgrid_segmentlight-bringer-blrlight-bringer-blraubreysineaubreysineed-twilion-npmed-twilion-npmharsh-joshi99harsh-joshi99irfan.ali.segmentirfan.ali.segmentkbhargavaram-sgkbhargavaram-sgneedcaffeineneedcaffeinenat-gridnat-gridwlumsegmentwlumsegmentmoyara2moyara2bala.singareddybala.singareddyakash.gautam07akash.gautam07preetyppreetypviveksainaneesegmentviveksainaneesegmentmsarafmsarafkjoerreskjoerresrokatyalrokatyalainatancincoainatancincoanton-vylushchakanton-vylushchaksowjanyasegmentsowjanyasegmentalayvoraalayvoratw-dgarciatw-dgarciaparag.pandaparag.pandablangtwilioblangtwilioryanrouleau-segmentryanrouleau-segmenttwjosiahtwjosiahmcullenmeyermcullenmeyerdavid.anusontarangkul.segmentdavid.anusontarangkul.segmentmckern_segmentmckern_segmentsegment-adminsegment-adminnainy.agrawalnainy.agrawaltdibaccotdibaccosudojatinsudojatinnageshgolemnageshgolembrandonheyer-segmentbrandonheyer-segmentalfrimpongalfrimpongdobrin.ganevdobrin.ganevankit.gupta.unthinkableankit.gupta.unthinkablemarinheromarinherobenattwiliobenattwiliobharath.boregowdabharath.boregowdaconniechenconniechensungju.jinsungju.jinpooyajpooyajyli119yli119ea_segmentea_segmentemilyjiaemilyjiakx-segmentkx-segmentxinghao.huangxinghao.huangharsh.vardhanharsh.vardhanjoe.ayoub.segmentjoe.ayoub.segmentgkochar123gkochar123rollcoderollcodeariel.silvestriariel.silvestricherylj-segmentcherylj-segmentimmanojimmanojaaronklishaaronklishmichelrmichelrmaneesh.dharma29maneesh.dharma29brianhumphreystwiliobrianhumphreystwiliojfehrman.segmentjfehrman.segmentjoetessyjoetessypmuninpmuninjalexy12jalexy12jbandi-twiliojbandi-twilioprayansh-twilioprayansh-twiliodominicbarnesdominicbarnesbrandon.scott-segmentbrandon.scott-segmentbgillanbgillanphillip.thomasphillip.thomasricardo.rossiricardo.rossiforgetfulfellowforgetfulfellowfauzy.yyfauzy.yymayur-pitalemayur-pitaledbaik-twilio-segmentdbaik-twilio-segmentseg-rustybaileyseg-rustybaileytanya.gupta.segmenttanya.gupta.segmentpmiller-twiliopmiller-twilionevermore2022nevermore2022aishikawakiaishikawakicsayusocsayusomcoulibalimcoulibalishupadhyayshupadhyayjahood-twiliojahood-twiliosaisagarkappaganthulasaisagarkappaganthularmukundanrmukundanarubiochavezarubiochavezshuvrajit9904shuvrajit9904s3gm3nts3gm3ntama0223ama0223tbrennanjtbrennanjdangmai-segmentdangmai-segmentshraddha-twilioshraddha-twiliosa-jsootersa-jsooterenyi.asonyeenyi.asonyeafsha-nazim-segafsha-nazim-segmschaszbergermschaszbergerlnambalnambavaradarajan-twvaradarajan-twseanhan-segmentseanhan-segmentreplateroreplaterosayan-das-insayan-das-injusteenjusteenjgabe13jgabe13meg1000meg1000funlufunluashwitha.bgashwitha.bgwhaider_twiliowhaider_twiliotcgilberttcgilbertkevinburkesegmentkevinburkesegmentfelttripfelttripprabhnoor1997prabhnoor1997akashyap91akashyap91clintz.segclintz.segkarimkeshwanikarimkeshwaniwally.tgwally.tgrhall-twiliorhall-twilioyash-twilioyash-twiliobrookstaylorjrbrookstaylorjrshayan-golafshanishayan-golafshanilerahulramlerahulrammugelstadmugelstadrrivera-segmentrrivera-segmentsethnutetwiliosethnutetwiliomanali-bhosalemanali-bhosalechtoombschtoombssethsegmentsethsegmenteric-hydeeric-hydeelmoselyeeelmoselyeemichaelghsegmichaelghsegjayakrishnannairjayakrishnannairlateefatlateefatmaryam.sharifmaryam.sharifwdbettswdbettsryanligonryanligonsindhusegmentsindhusegmentlfdelossantoslfdelossantosaramakrishnanaramakrishnanvbatanovvbatanovlluque-twiliolluque-twiliojair.avilesjair.avilespmaidpmaidsong4yousong4youpeterdemartinipeterdemartiniemmy.byrneemmy.byrnevincen7tranvincen7trandean-huynhdean-huynhcdignam-segmentcdignam-segmentabhinavsurekaabhinavsurekaarunlalam-segmentarunlalam-segmentneeharikakondipatineeharikakondipatisimpixelatedsimpixelatedchihchun-twiliochihchun-twilioacharles14acharles14jyim008jyim008fhalim-segmentfhalim-segmentcfreecfreehjoonpmhjoonpmceline-segmentceline-segmentpmcanseco-segmentpmcanseco-segmentmasiramasiraamillet89amillet89cholt002cholt002av-segmentav-segmentaghotikaraghotikarvikrant-segmentvikrant-segmentlarryatsegmentlarryatsegmentscruwys1scruwys1kyliepedersenkyliepedersenjinaparkjinaparksegmentiosegmentiorajulvaderarajulvaderalpediredlalpediredlan2parkon2parkotyson_segmenttyson_segmentbgamwellbgamwellsalolivaressalolivareserikdwerikdwchenxiangzhangchenxiangzhangmericssonmericssonprayansh-segmenttprayansh-segmenttjeremylarkinjeremylarkinbsneedbsneeddanieljackinsdanieljackinssegment-sethsegment-sethjames9446james9446priscilla.giattipriscilla.giattinlsunnlsundrew-thompsondrew-thompsonsegment-jsinghsegment-jsinghandrius-segmentandrius-segmentvalerieernstvalerieernstgilomergilomermarcelopvmarcelopveric.rognereric.rognerkdharaiyakdharaiyajon.anderson-at-segment.comjon.anderson-at-segment.comstacy.songstacy.songrexatsegmentrexatsegmentnickaguilarnickaguilarbradenbeckerbradenbeckerreneewangreneewangdan.laskydan.laskysam.tapiasam.tapiavikramkumar19vikramkumar19mpriyad25mpriyad25jeremy.parkerjeremy.parkersmidgessmidges

Readme

analytics.js-integration

CircleCI Codecov

The base integration factory used to create custom analytics integrations for Analytics.js.

The factory returns a barebones integration that has no logic, so that we can share common pieces of logic—like queueing before an integration is ready, providing a way to default options, etc—in one place.

Integrating with Segment

Interested in integrating your service with us? Check out our Partners page for more details.

Example

var integration = require('@segment/analytics.js-integration');

var Custom = integration('Custom Analytics')
  .global('_custom')
  .assumesPageview()
  .readyOnInitialize();

Custom.prototype.track = function (event, properties) {
  window._custom.push(['track', event, properties]);
};

Facade

This library relies on segmentio/facade which is a helper that makes working with the input to Analytics.js easier, by handling lots of common cases in one place.

API

integration(name)

Create a new Integration constructor with the given integration name. name is the key with which users can initialize the integration.

.option(key, default)

Register a new option for the integration by key, with a default value.

.mapping(key)

Add a new mapping option by key. The option will be an array that the user can pass in of key -> value mappings. This will also generated a #KEY method on the integration's prototype for easily accessing the mapping.

For example if your integration only supports a handful of events like Signed Up and Completed Order, you might create an mapping option called events that the user would pass in, like so:

var MyIntegration = Integration('MyIntegration')
  .mapping('events');

Which means that when the integration is initialized, it would be passed a mapping of events to use, like so:

new MyIntegration({
  events: [
    { key: 'Signed Up', value: 'Register' },
    { key: 'Completed Order', value: 'Purchase' }
  ]
});

Then later on, you can easily get all of the entries with a specific key, by calling this.events(key). For example:

MyIntegration.prototype.track = function(track){
  var matches = this.events(track.event());
  each(matches, function(value){
    window._myglobal.push(value);
  });
};

.global(key)

Register a new global variable key that the Integration uses. If this key already exists on window when initialize is called, it will return early, thus ensuring that setup logic and libraries aren't loaded twice.

.assumesPageview()

Mark the Integration as assuming an initial pageview has happened when its Javascript library loads. This is important for integrations whose libraries assume a "pageview" in their interface as soon as the library loads, instead of exposing a .page() method or similar to call via Javascript.

This option changes the integration so that the very first call to page actually initializes the integration, ensuring that the pageviews aren't accidentally duplicated.

.readyOnInitialize()

Mark the Integration as being ready to accept data after initialize is called. This is true of integrations that create queues in their snippets so that they can record data before their library has been downloaded.

.readyOnLoad()

Mark the Integration as being ready to accept data after load is called. This is true for integrations that need to wait for their library to load on the page to start recording data.

#initialize([page])

Initialize the integration. This is where the typical 3rd-party Javascript snippet logic should be. If the integration assumes an initial pageview, initialize will be called with the page method's arguments.

#load([callback])

Load the integration's 3rd-party Javascript library, and callback(err, e). The loading logic should be pulled out of the snippet from initialize and placed here.

#identify(facade)

Identify the current user for the integration given an Identify facade. See the identify method docs for more information.

#group(facade)

Group the current account/organization/group/etc for the integration given an Group facade. See the group method docs for more information.

#page(facade)

Transform a Page facade into a page view for the integration. See the page method docs for more information.

Identify a user.

#track(facade)

Track an event with the integration, given a Track facade. See the track method docs for more information.

#alias(facade)

Alias two user identities given an Alias facade. See the alias method docs for more information.