Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add google analytics to react

Bash/CMD: yarn add react-ga

//useAnalyticsEventTracker.jsx

import React from "react";
import ReactGA from "react-ga";

const AnalyticsEventTracker = (category="Blog category") => {
  const eventTracker = (action = "test action", label = "test label") => {
    ReactGA.event({category, action, label});
  }
  return eventTracker;
}
export default AnalyticsEventTracker;

//ContactUs.jsx
import AnalyticsEventTracker from './AnalyticsEventTracker';

const ContactUs = () => {
  const gaEventTracker = AnalyticsEventTracker('Contact us');
  return(
  <div>
    <h3>Contact Us</h3>
     <div> 
       <a href="#" onClick={()=>gaEventTracker('call')}>Call Us</a>
      </div>
     <div>
       <a href="mailto:someone@example.com" onClick={()=>gaEventTracker('email')}>Write to us</a>
      </div>
  </div>)
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: append to map javascript 
Javascript :: change url angular 
Javascript :: javascript include property array object 
Javascript :: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import 
Javascript :: how to allow implicit any in .d.ts 
Javascript :: convert set to array javascript 
Javascript :: printing in a single line in javascript 
Javascript :: how to add a white space in jsx 
Javascript :: angular detect chromebook 
Javascript :: make object readonly javascript 
Javascript :: yup string date schema validation 
Javascript :: json deep dot 
Javascript :: how to make a github api using react 
Javascript :: react hide element 
Javascript :: how to replace all occurrences of a string in javascript 
Javascript :: append http to url 
Javascript :: Javascript - convert string value to lowercase 
Javascript :: Difference in months between two dates in Javascript 
Javascript :: logic operators in javascript 
Javascript :: how to include script file in javascript with javascript 
Javascript :: iife in javascript 
Javascript :: regex[ress for password 
Javascript :: javascript get character from string 
Javascript :: node assert 
Javascript :: const is available in es6 
Javascript :: jquery plugin for searchable dropdown 
Javascript :: object check null or empty 
Javascript :: javascript add id to element with class 
Javascript :: js copy values from one array to another node new 
Javascript :: nestjs set swagger api keys 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =