Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added react (ts/js) examples #6

Open
wants to merge 2 commits into
base: initialSetup_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Contentsquare TAG SDK

This NPM package offers developers a standardized way of loading Tracking TAG in a non-blocking way from remote
servers. Based on the [Contentsquare SDK](https://docs.contentsquare.com/uxa-en/).

Contentsquare is an analytics platform that helps businesses understand and optimize user experiences on their websites and mobile apps. It provides actionable insights through heatmaps, session recordings, and behavioral analytics, allowing businesses to identify areas for improvement and enhance overall website performance. With its user-friendly interface and powerful data visualization, Contentsquare enables data-driven decision-making to boost conversions and enhance customer engagement.


## Installation

Install the package using NPM:

```console
npm install --save @contentsquare/tag-sdk
```



-------------

## How to Use Contentsquare Tag


### Prerequisites

Before using the Contentsquare tag, make sure you have the following:

- **Contentsquare Account**: Sign up for a Contentsquare account on official website (https://www.contentsquare.com/) and obtain your client ID.

- **Access to Website Code**: You'll need access to your website's codebase to add the Contentsquare tag.

### Steps to Use Contentsquare Tag

Follow the steps below to use the Contentsquare tag on your website:

1. **Include the Contentsquare Script**: In your website's Javascript/Typescript, add the Contentsquare script using the provided client ID. Replace `YOUR_CLIENT_ID` with your actual Contentsquare client ID.

Call the `injectContentsquareScript` function with the necessary options to append the Contentsquare script to the document.head.

```javascript
// Replace 'YOUR_CLIENT_ID' with your actual Contentsquare client ID
injectContentsquareScript({
clientId: 'YOUR_CLIENT_ID',
async: true, // Optional: Set to false to wait for script execution until after document parsing.
defer: false, // Optional: Set to true to defer script execution after document parsing.
integrity: 'YOUR_SCRIPT_INTEGRITY_HASH', // Optional: Provide the integrity hash for script security (if required).
});
```

The function will append the Contentsquare script to the document.head, and it will be fetched and executed accordingly based on the provided options.


2. **Trigger Page View Tracking**: Once the Contentsquare script is included on your website, it automatically tracks page views by default. No additional code is required to track basic page views.

3. **Track Custom Events**: Use the Contentsquare JavaScript API to track custom events on your website. For example, you can track clicks, form submissions, video interactions, and other user interactions. Refer to the Contentsquare documentation for details on how to use API.


```html
<!-- Example: Tracking a click event -->
<script>
window._uxa = window._uxa || [];
window._uxa.push(['trackEvent', 'CLICK_EVENT_NAME']);
</script>

```

4. **User Identification**: To associate user behavior with specific users, you can set the user ID using the `setUserId` method. This allows you to analyze the behavior of individual users in your analytics.

```html
<!-- Example: Setting the user ID -->
<script>
window._uxa = window._uxa || [];
window._uxa.push(['setUserId', 'USER_ID']);
</script>
```

5. **View Analytics Reports**: After implementing the Contentsquare tag on your website, you can log in to your Contentsquare account and access detailed analytics reports, including heatmaps, session replays, conversion funnels, and more.

## Additional Configuration (Optional)

The Contentsquare tag provides additional configuration options to customize your analytics tracking. Refer to the [Contentsquare documentation](https://docs.contentsquare.com/uxa-en/) for more information on configuring advanced settings, enabling specific modules, and handling specific use cases.

---


## API Reference

### `injectContentsquareScript(scriptOptions)`

Injects the Contentsquare script into the document.head.

- `scriptOptions`: Options for injecting the script.
- `clientId` (string) - **(Required)** The client ID provided by Contentsquare in the form of 'a6f73d509'.
- `defer` (boolean) - (Optional) Indicates if the script is fetched in parallel and evaluated after the document is parsed. Defaults to `false`.
- `async` (boolean) - (Optional) Indicates if the script is fetched in parallel and evaluated as soon as possible. Defaults to `true`.
- `integrity` (string) - (Optional) The integrity hash (SRI) of the Contentsquare script. Must be generated by Contentsquare.

**Returns**: The script element representing the Contentsquare script that was appended to `document.head`. Can be used for further manipulation or tracking loading state.

## Restrictions
* This bootstrap mode will only be available for the modern “Contentsquare Deployment” mode (no support for Clicktale or any other legacy modes).
* Some functions within the package will include inline descriptions/types for ease of use, but not all functionality is covered. Please refer to the official [Contentsquare documentation](https://docs.contentsquare.com/uxa-en/) for more information on the available functions and their usage.

## License

This utility is open-source and distributed under the Copyrighted License. Please don't modify or redistribute the code without explicit permission from Contentsquare.

---

23 changes: 23 additions & 0 deletions examples/cs-react-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
46 changes: 46 additions & 0 deletions examples/cs-react-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
Loading