title: How to Use Google Analytics in ReactJs Application to Track Events
body: <p>I want to track link in component clicks using Google Analytics in my reactjs app. I did below steps:</p>
  <ol>
  <li><p>npm install react-ga --save</p>
  </li>
  <li><p>import ReactGA from 'react-ga';
  ReactGA.initialize('UA-mytrackId');</p>
  </li>
  <li><p>my index.html has javascript code:</p>
    
  
   var trackOutboundLink = function(url) {
    ga('send', 'event', 'outbound', 'click', url, {
    'transport': 'beacon',
    'hitCallback': function(){document.location = url;}
   });
   }
   
  </li>
  </ol>
  <p>How to track the ,  clicks in my component below:</p>
  <pre><code>import React from 'react';
  import { Link} from 'react-router-dom';
  const CourseDetail=({course, onCourseSelect})=&gt;{
  return (    
     &lt;div&gt;
       {course.SUBJECT} {course.CATALOG_NBR} - {course.COURSE_DESCR} 
       &lt;ViewLink onCourseSelect={onCourseSelect} course={course}&gt;&lt;/ViewLink&gt;
       &lt;Link  to={{ pathname: '/course/'+course.CLASS_NBR
               
              }}
              target=&quot;_blank&quot;
                          key={course.ID} onClick={()=&gt;&quot;ga('create', 'UA-mytrackId'); ga('send',   'event', 'Schedule', 'bookmarksClick', 'bookmarks');&quot;} &gt;
                          Bookmark link
                      &lt;/Link&gt;
      &lt;/div&gt;  
  );
  };
  export default CourseDetail;
  
      
  </code></pre>