-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add the documentation about it
- Loading branch information
1 parent
5b8e3ba
commit e4e6d00
Showing
2 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,82 @@ | ||
# React HubSpot Tracking Code Hook | ||
|
||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
|
||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-) | ||
|
||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
|
||
A custom hook to use the HubSpot Tracking Code API function. | ||
|
||
With this custom hook, you can easily use the [HubSpot Tracking Code API](https://developers.hubspot.com/docs/api/events/tracking-code) function. | ||
|
||
## Features | ||
|
||
- [x] Set Page Path | ||
- [x] Track Page View | ||
- [x] Identify a visitor | ||
|
||
## Guide | ||
|
||
- [React HubSpot Tracking Code Hook](#react-hubspot-tracking-code-hook) | ||
- [Features](#features) | ||
- [Guide](#guide) | ||
- [Installation](#installation) | ||
- [How to use](#how-to-use) | ||
- [Basic](#basic) | ||
- [API](#api) | ||
- [License](#license) | ||
- [Contributors ✨](#contributors-) | ||
|
||
## Installation | ||
|
||
First step, install the HubSpot tracking code in your React project following the [HubSpot documentation](https://knowledge.hubspot.com/reports/install-the-hubspot-tracking-code) about it. | ||
|
||
_Tips: You can copy and paste the script code directly in the `public/index.html` file or use the Google Tag Manager to install as a pixel._ | ||
|
||
then, | ||
|
||
```bash | ||
$ yarn add react-hubspot-tracking-code-hook | ||
# or | ||
$ npm install react-hubspot-tracking-code-hook | ||
``` | ||
|
||
## How to use | ||
|
||
This library is using the global function `window._hsq` that's initialized from HubSpot tracking code. | ||
|
||
#### Basic | ||
|
||
```typescript jsx | ||
import React from "react"; | ||
import { useTrackingCode } from "react-hubspot-tracking-code-hook"; | ||
|
||
const App = () => { | ||
const { setPathPageView, setIdentity } = useTrackingCode(); | ||
|
||
setPathPageView("/home"); | ||
|
||
setIdentity("[email protected]"); | ||
|
||
return <div>My app</div>; | ||
}; | ||
``` | ||
|
||
## API | ||
|
||
`useTrackingCode` provides the functions from HubSpot tracking code; | ||
|
||
| Name | Params | Required | Info | | ||
| ------------------ | ------------------------------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `setPathPageView` | `pathName: string` | **YES** | Set the path to the current page will be treated. This function should be used to update the current page whenever a page is loaded. After using this function to update the path, it will call the `setTrackPageView` function to track the view of the current page. | | ||
| `setTrackPageView` | | | This function is called when the tracking code is loaded on a page, but you can manually call this function to track subsequent views in a single page application. | | ||
| `setIdentity` | `(email: string, otherProperties: object)` | **email: YES** | This function is used to identify a visitor to your site. The unique identifier is an email address. If there is an existing contact record for that email address, it will be updated. Otherwise, a new contact record will be created. In both cases, the analytics data collected for the visitor will be associated with the contact record. | | ||
|
||
## License | ||
|
||
`react-hubspot-tracking-code-hook` is under MIT License | ||
|
||
## Contributors ✨ | ||
|
||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): | ||
|
@@ -22,4 +95,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d | |
|
||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
|
||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"name": "react-hubspot-tracking-code-hook", | ||
"version": "1.0.0", | ||
"repository": "https://github.com/kelvinmaues/react-hubspot-tracking-code-hook.git", | ||
"homepage": "https://github.com/elgorditosalsero/react-gtm-hook#readme", | ||
"author": "Kelvin Maues <[email protected]>", | ||
"version": "1.0.0", | ||
"repository": "https://github.com/kelvinmaues/react-hubspot-tracking-code-hook", | ||
"homepage": "https://github.com/elgorditosalsero/react-hubspot-tracking-code-hook#readme", | ||
"license": "MIT", | ||
"keywords": [ | ||
"react", | ||
|
@@ -12,9 +12,10 @@ | |
"hubspot hook", | ||
"hubspot tracking code", | ||
"tracking code", | ||
"hubspot use tracking code" | ||
"hubspot tracking code hook", | ||
"react hubspot tracking code hook" | ||
], | ||
"description": "The HubSpot tracking code function as hook to use in your React project (SPA) with all the functions available in the HubSpot Tracking code API documentation.", | ||
"description": "The HubSpot tracking code function as a hook to use in your React project (SPA) with all the functions available in the HubSpot Tracking code API documentation.", | ||
"main": "dist/index.js", | ||
"module": "dist/react-hubspot-tracking-code-hook.esm.js", | ||
"typings": "dist/index.d.ts", | ||
|