@segment/snippet
TypeScript icon, indicating that this package has built-in type declarations

4.16.0 • Public • Published

Circle CI

snippet

Render the analytics.js snippet.

The recommended way to use analytics.js is to follow the analytics.js quickstart guide. If you absolutely need to generate a snippet dynamically, this is an alternate solution. Note that when using this in-browser, the global analytics object will not be defined until the snippet is rendered and executed.

This package is supported on IE8+, Chrome, Firefox, Safari 9, Microsoft Edge, Node.js 0.10+

For IE7 support, install a global JSON polyfill on the page prior to loading this package.

Example

var snippet = require('@segment/snippet');

var contents = snippet.max({
  host: 'cdn.segment.com',
  apiKey: '03fwkuu3',
  page: {
    category: 'Docs',
    name: 'Integrations',
    properties: {
      foo: 'bar'
    }
  }
});

API

snippet.max(options)

Returns the maxified version of the analytics.js snippet given a set of options:

  • host: the domain name where the analytics.js script is hosted.
  • useHostForBundles: If set to true, the snippet will include the _cdn property to tell analytics.js where to fetch bundles from.
  • apiKey: the apiKey to load in the snippet.
  • page: the options to pass to analytics.page. if page is false, then the page() call will be omitted.
  • load: if set to false the load() call will be omitted. This is useful for if you want dynamically control the load process on the client-side for things like GDPR.
  • ajsPath: override the default analytics.min.js location

snippet.min(options)

Returns the minified version of the snippet.

Keywords

none

Install

npm i @segment/snippet

DownloadsWeekly Downloads

79,294

Version

4.16.0

License

MIT

Unpacked Size

29.1 kB

Total Files

18

Last publish

Collaborators

  • jrupasinghe
  • myrontin.segment
  • devthale
  • smccoy-twilio
  • akurapati-segment
  • seg-leonelsanches
  • psankaranarayanan
  • jibrang
  • sethgrid_segment
  • light-bringer-blr
  • aubreysine
  • ed-twilion-npm
  • harsh-joshi99
  • irfan.ali.segment
  • kbhargavaram-sg
  • needcaffeine
  • nat-grid
  • spandananune92
  • wlumsegment
  • vivek-26
  • moyara2
  • bala.singareddy
  • gbbastos
  • sprasannasastry22
  • akash.gautam07
  • preetyp
  • viveksainaneesegment
  • msaraf
  • kjoerres
  • rokatyal
  • ainatancinco
  • anton-vylushchak
  • sowjanyasegment
  • alayvora
  • pzawadzki
  • msaunders-segment
  • tw-dgarcia
  • bvakkalagadda
  • mbreske
  • nsandhu-segment
  • parag.panda
  • blangtwilio
  • ryanrouleau-segment
  • twjosiah
  • mcullenmeyer
  • nina-y
  • david.anusontarangkul.segment
  • mckern_segment
  • segment-admin
  • nainy.agrawal
  • tdibacco
  • sudojatin
  • nageshgolem
  • brandonheyer-segment
  • teganduong
  • alfrimpong
  • dobrin.ganev
  • ankit.gupta.unthinkable
  • marinhero
  • benattwilio
  • bharath.boregowda
  • conniechen
  • sungju.jin
  • pooyaj
  • yli119
  • ea_segment
  • emilyjia
  • kx-segment
  • cvillela_segment
  • xinghao.huang
  • harsh.vardhan
  • joe.ayoub.segment
  • gkochar123
  • rollcode
  • ariel.silvestri
  • cherylj-segment
  • leifdreizler
  • immanoj
  • aaronklish
  • michelr
  • maneesh.dharma29
  • msolorzano-segment
  • brianhumphreystwilio
  • jfehrman.segment
  • joetessy
  • pmunin
  • jalexy12
  • jbandi-twilio
  • prayansh-twilio
  • dominicbarnes
  • brandon.scott-segment
  • bgillan
  • phillip.thomas
  • ricardo.rossi
  • forgetfulfellow
  • fauzy.yy
  • mayur-pitale
  • dbaik-twilio-segment
  • seg-rustybailey
  • tanya.gupta.segment
  • pmiller-twilio
  • nevermore2022
  • aishikawaki
  • csayuso
  • mcoulibali
  • shupadhyay
  • swgupta
  • sumit1606
  • jahood-twilio
  • saisagarkappaganthula
  • dostwal
  • rmukundan
  • ngoldman-twilio
  • apareek-twilio
  • arubiochavez
  • shuvrajit9904
  • s3gm3nt
  • ama0223
  • tbrennanj
  • dangmai-segment
  • shraddha-twilio
  • taricjain
  • snehauppalapati
  • nitish.dubey
  • azhaotwilio
  • ryder.wendt
  • sa-jsooter
  • enyi.asonye
  • afsha-nazim-seg
  • akurapati
  • mschaszberger
  • lnamba
  • varadarajan-tw
  • seanhan-segment
  • replatero
  • sayan-das-in
  • justeen
  • sausingh
  • jgabe13
  • haeyoon.paik
  • kentrollins
  • meg1000
  • funlu
  • ashwitha.bg
  • whaider_twilio
  • tcgilbert
  • kevinburkesegment
  • felttrip
  • prabhnoor1997
  • akashyap91
  • connormarchand
  • clintz.seg
  • karimkeshwani
  • wally.tg
  • rhall-twilio
  • yash-twilio
  • brookstaylorjr
  • shayan-golafshani
  • lerahulram
  • shpankau
  • mugelstad
  • hdamani
  • brchristy
  • rrivera-segment
  • sethnutetwilio
  • fplinke
  • manali-bhosale
  • chtoombs
  • sethsegment
  • eric-hyde
  • elmoselyee
  • michaelghseg
  • jayakrishnannair
  • lateefat
  • maryam.sharif
  • wdbetts
  • ryanligon
  • sindhusegment
  • lfdelossantos
  • aramakrishnan
  • segment-camden
  • vbatanov
  • lluque-twilio
  • jair.aviles
  • pmaid
  • song4you
  • peterdemartini
  • emmy.byrne
  • vincen7tran
  • dean-huynh
  • cdignam-segment
  • abhinavsureka
  • rikezatsegment
  • arunlalam-segment
  • cjradek
  • neeharikakondipati
  • simpixelated
  • chihchun-twilio
  • acharles14
  • jyim008
  • seghungtran
  • tv0
  • hema-segment
  • oscb
  • krousseau
  • sachinwathore
  • fhalim-segment
  • cfree
  • hjoonpm
  • celine-segment
  • parsa-segment
  • pmcanseco-segment
  • ynguyen
  • masira
  • amillet89
  • cholt002
  • av-segment
  • aghotikar
  • vikrant-segment
  • larryatsegment
  • lbrink
  • shivpoojan-segment
  • ariel_segment
  • scruwys1
  • lew-gordon
  • kyliepedersen
  • jinapark
  • segmentio
  • rajulvadera
  • lpediredla
  • n2parko
  • sahilp
  • psankaranarayana
  • tyson_segment
  • bgamwell
  • uditmehta
  • salolivares
  • erikdw
  • chenxiangzhang
  • mericsson
  • prayansh-segmentt
  • jeremylarkin
  • bsneed
  • danieljackins
  • segment-seth
  • james9446
  • priscilla.giatti
  • kellylu
  • nlsun
  • drew-thompson
  • segment-jsingh
  • andrius-segment
  • valerieernst
  • khinkalilover
  • kelcook
  • alistairbarrell
  • gilomer
  • marcelopv
  • eric.rogner
  • kdharaiya
  • jon.anderson-at-segment.com
  • markzegarelli
  • stacy.song
  • niveda.balananthan
  • rexatsegment
  • nickaguilar
  • bradenbecker
  • reneewang
  • dan.lasky
  • sam.tapia
  • vikramkumar19
  • mpriyad25
  • jeremy.parker
  • khamidou-segment
  • smidges