Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
/ react-simple-gtm Public archive

Adding Google Tag Manager service to React App made easy

License

Notifications You must be signed in to change notification settings

teonite/react-simple-gtm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-simple-gtm

Adding Google Tag and Google Tag Manager service to React App made easy

Installation

npm install --save react-simple-gtm

Usage

in your app entrypoint (e.x. index.jsx)

import TagProvider from 'react-simple-gtm';

//...

ReactDOM.render(
    // ... other providers
    <TagProvider gtagId="<your_gtag_tracking_id" gtmId="<yout_google_tag_manager_id>">
        // your application or router
    </TagProvider>
    // ...
    , 
    document.getElementById('root'),
);

then, in your components

import {injectTag, tagShape} from 'react-simple-gtm';

const MyAwesomeComponent = ({tag}) => (
    <button onClick={() => tag.push('event', 'click_me_btn_clicked')}>
        Click Me
    </button>
)

MyAwesomeComponent.propTypes = {
    tag: tagShape,
}

export default injectTag(MyAwesomeComponent);

License

MIT

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •