GithubHelp home page GithubHelp logo

segmentio / analytics-react Goto Github PK

View Code? Open in Web Editor NEW
158.0 6.0 23.0 1.06 MB

[DEPRECATED AND UNSUPPORTED] The hassle-free way to integrate analytics into your React application.

Home Page: https://segment.com

License: MIT License

HTML 23.33% CSS 8.41% JavaScript 68.26%
segment react create-react-app analytics react-boilerplate quickstart

analytics-react's People

Contributors

f2prateek avatar sanscontext avatar williamgrosset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

analytics-react's Issues

Programmatically Inject Analytics.js

Is there a way to programmatically inject the analytics.js snippet into my app versus just blindly importing it into my index.html? I have certain pages that I don't want 3rd party scripts to be loaded onto.

What is the purpose of this repo?

Hi,

I had a look at the README and the source code and can't figure out why this repo exists. I can't find a single importable React component in the source code. It's just an example project using Create React App. Why have a package on NPM at all?

Enable/Disable Analytics in development ?

I'm working on my team workflow for analytics and i'm looking for a way to Enable/Disable analytics in development environment.

//package.json
    "start": "react-scripts start",
    "start:analytics": "REACT_APP_SEGMENT="Dev key" react-scripts start",

This seems to work but i don't really understand how analytics script work behind the hood but it seems to save all analytics events done even if the script doesn't load .

Is this acceptable or could you show me how to prevent sending data in this case ?

Localhost implementation?

Hi all, looking to integrate this locally, using the header like so:

<script>
        !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var t=analytics.methods[e];analytics[t]=analytics.factory(t)}analytics.load=function(e,t){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+e+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=t};analytics.SNIPPET_VERSION="4.1.0";
        analytics.load("mykey");
        analytics.page();
        }}();
    </script>

and then using react stateless functional components and calling the event tracking like so:
function trackEvent(){ window.analytics.track('New Diagnosis'); console.log("New Diagnosis Tracked") }

The console.log works but the data does not show up in my dashboard

staging vs production in Create React App?

On segmnet, you suggest creating two sources for different environments.

For this package, you have to put the tag in the public folder.

As far as I understand Create react app doesn't let you use environment variable in the public folder.

This means I have to manually copy and paste the script tag in every time I want to switch between environments. If I mess this up and forget just once it's going to introduce a bunch of nonsense into my analytics. Is there a better way to do this?

Why is this repo labelled react if we just use the same js tag as everyone else?

Running segment on localhost:3000

I'm trying to test my Segment configuration on localhost:3000, but I'm not getting any data coming in. Is it not possible to use localhost as a source?

Snippet doesn't work with JSX

We really need a React-based approach to this library, the snippet that is assigned in the project's config will fail JSX formatting rules.

Either segment should update their global script tag snippet, or this library should provide a JSX friendly way to implement Segment.

  42 |           <script type="text/javascript">
> 43 |             !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
     |                         ^
  44 |             analytics.load("YOUR_WRITE_KEY");
  45 |             // analytics.page() // Uncomment if your application is NOT an SPA
  46 |             }}();
AMP bind syntax []='' is not supported in JSX, use 'data-amp-bind-' instead. https://err.sh/zeit/next.js/amp-bind-jsx-alt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.