Skip to content

Commit

Permalink
Replace all occurrences of hotjar with contentsquare.
Browse files Browse the repository at this point in the history
  • Loading branch information
yasslavov committed Jun 17, 2024
1 parent 447d6e5 commit 1526200
Show file tree
Hide file tree
Showing 13 changed files with 8,079 additions and 4,923 deletions.
Binary file modified .DS_Store
Binary file not shown.
22 changes: 2 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 1.0.9 (2023-06-08)

### 1.0.8 (2023-06-08)

### 1.0.7 (2023-02-15)

### 1.0.6 (2022-05-30)

### 1.0.5 (2021-12-08)

### 1.0.4 (2021-12-08)

### 1.0.3 (2021-05-14)

### 1.0.2 (2021-05-14)

### [1.0.1](https://github.com/hotjar/hotjar-js/compare/v1.0.0...v1.0.1) (2021-05-13)

## 1.0.0 (2021-05-13)
## 1.0.0 (2024-06-20)

### Features

- package setup + init + isReady methods ([168f0f4](https://github.com/hotjar/hotjar-js/commit/168f0f4ddc5e6fcf089e7bc03c5eac20a074a31f))
- Package setup + init
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Hotjar
Copyright (c) 2024 Contentsquare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
# @hotjar/browser
# @contentsquare/browser

[![@hotjar/browser](https://img.shields.io/npm/v/@hotjar/browser.svg?label=@hotjar/browser)](https://www.npmjs.com/package/@hotjar/browser)
[![@contentsquare/browser](https://img.shields.io/npm/v/@contentsquare/browser.svg?label=@contentsquare/browser)](https://www.npmjs.com/package/@contentsquare/browser)

> Bring [Hotjar](https://www.hotjar.com/) directly to your application
> Bring [Contentsquare](https://www.contentsquare.com/) directly to your application
## Installation

Add this package as a dependency in your project, then import the library in your code.

```bash
yarn add @hotjar/browser
yarn add @contentsquare/browser
```

```javascript
import Hotjar from '@hotjar/browser';
import Contentsquare from '@contentsquare/browser';
```

## Initialize Hotjar
## Initialize Contentsquare

In order for Hotjar to run, it needs to be initialized with your site ID.
In order for Contentsquare to run, it needs to be initialized with your site ID.
You can find your site ID on [this page](https://insights.hotjar.com/site/list) just before your site name.

```javascript
const siteId = 123;
const hotjarVersion = 6;
const contentsquareVersion = 6;

Hotjar.init(siteId, hotjarVersion);
Contentsquare.init(siteId, contentsquareVersion);

// Initializing with `debug` option:
Hotjar.init(siteId, hotjarVersion, {
Contentsquare.init(siteId, contentsquareVersion, {
debug: true
});
```

## Identify API

One of the main interest of this library is to be able to use [Hotjar Identify API](https://help.hotjar.com/hc/en-us/articles/360033640653-Identify-API-Reference).
One of the main interest of this library is to be able to use [Contentsquare Identify API](https://help.hotjar.com/hc/en-us/articles/360033640653-Identify-API-Reference).

```javascript
const userId = 'abc_123';
const firstName = 'John';
const favoriteColor = 'blue';

Hotjar.identify(userId, {
Contentsquare.identify(userId, {
first_name: firstName,
color: favoriteColor,
});
```

## Events API

You can also track specific actions taken by your users and send that data to Hotjar via the [Hotjar Events API]("https://help.hotjar.com/hc/en-us/articles/4405109971095-Events-API-Reference").
You can also track specific actions taken by your users and send that data to Contentsquare via the [Contentsquare Events API]("https://help.hotjar.com/hc/en-us/articles/4405109971095-Events-API-Reference").

```javascript
const actionName = 'error';
Hotjar.event(actionName);
Contentsquare.event(actionName);
```

## Manual URL changes

Depending on how your website routing works, you might need to manually instruct Hotjar when a route change has happened. [More details about URL changes](https://help.hotjar.com/hc/en-us/articles/360034378534).
Depending on how your website routing works, you might need to manually instruct Contentsquare when a route change has happened. [More details about URL changes](https://help.hotjar.com/hc/en-us/articles/360034378534).

```javascript
const newPage = '/new';

Hotjar.stateChange(newPage);
Contentsquare.stateChange(newPage);
```

## CSP

If the project uses [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), you can add a special string to your server response headers so that the HotJar script loads without problems
If the project uses [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), you can add a special string to your server response headers so that the Contentsquare script loads without problems

```javascript
// Initializing with `nonce` option:
Hotjar.init(siteId, hotjarVersion, {
Contentsquare.init(siteId, contentsquareVersion, {
nonce: 'rAnDoM'
});
```
Expand Down
32 changes: 16 additions & 16 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import Hotjar from '../src/index';
import Contentsquare from '../src/index';
import * as utils from '../src/utils';

const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
const initSpy = jest.spyOn(utils, 'initScript');
const executeCommandSpy = jest.spyOn(utils, 'executeHotjarCommand');
const executeCommandSpy = jest.spyOn(utils, 'executeContentsquareCommand');

describe('Hotjar library', () => {
describe('Contentsquare library', () => {
it('should return methods', () => {
expect(Hotjar.init).toBeDefined();
expect(Hotjar.isReady).toBeDefined();
expect(Hotjar.event).toBeDefined();
expect(Hotjar.identify).toBeDefined();
expect(Hotjar.stateChange).toBeDefined();
expect(Contentsquare.init).toBeDefined();
expect(Contentsquare.isReady).toBeDefined();
expect(Contentsquare.event).toBeDefined();
expect(Contentsquare.identify).toBeDefined();
expect(Contentsquare.stateChange).toBeDefined();
});

describe('init', () => {
it('should init script and return true', () => {
initSpy.mockReturnValueOnce(undefined);
const init = Hotjar.init(123, 1);
const init = Contentsquare.init(123, 1);
expect(initSpy).toHaveBeenCalled();
expect(init).toBe(true);
});
it('should return false in case of error', () => {
initSpy.mockImplementationOnce(() => {
throw Error('error');
});
const init = Hotjar.init(123, 1);
const init = Contentsquare.init(123, 1);
expect(initSpy).toHaveBeenCalled();
expect(init).toBe(false);
expect(consoleErrorSpy).toHaveBeenCalled();
Expand All @@ -35,15 +35,15 @@ describe('Hotjar library', () => {
describe('event', () => {
it('should use event and return true', () => {
executeCommandSpy.mockReturnValueOnce(undefined);
const event = Hotjar.event('BugSplat!');
const event = Contentsquare.event('BugSplat!');
expect(executeCommandSpy).toHaveBeenCalled();
expect(event).toBe(true);
});
it('should return false in case of error', () => {
executeCommandSpy.mockImplementationOnce(() => {
throw Error('error');
});
const event = Hotjar.event('BugSplat!');
const event = Contentsquare.event('BugSplat!');
expect(executeCommandSpy).toHaveBeenCalled();
expect(event).toBe(false);
expect(consoleErrorSpy).toHaveBeenCalled();
Expand All @@ -53,15 +53,15 @@ describe('Hotjar library', () => {
describe('identify', () => {
it('should use identify and return true', () => {
executeCommandSpy.mockReturnValueOnce(undefined);
const identify = Hotjar.identify('321', { foo: 'bar' });
const identify = Contentsquare.identify('321', { foo: 'bar' });
expect(executeCommandSpy).toHaveBeenCalled();
expect(identify).toBe(true);
});
it('should return false in case of error', () => {
executeCommandSpy.mockImplementationOnce(() => {
throw Error('error');
});
const identify = Hotjar.identify('321', { foo: 'bar' });
const identify = Contentsquare.identify('321', { foo: 'bar' });
expect(executeCommandSpy).toHaveBeenCalled();
expect(identify).toBe(false);
expect(consoleErrorSpy).toHaveBeenCalled();
Expand All @@ -71,15 +71,15 @@ describe('Hotjar library', () => {
describe('stateChange', () => {
it('should use stateChange and return true', () => {
executeCommandSpy.mockReturnValueOnce(undefined);
const stateChange = Hotjar.stateChange('/my/url');
const stateChange = Contentsquare.stateChange('/my/url');
expect(executeCommandSpy).toHaveBeenCalled();
expect(stateChange).toBe(true);
});
it('should return false in case of error', () => {
executeCommandSpy.mockImplementationOnce(() => {
throw Error('error');
});
const stateChange = Hotjar.stateChange('/my/url');
const stateChange = Contentsquare.stateChange('/my/url');
expect(executeCommandSpy).toHaveBeenCalled();
expect(stateChange).toBe(false);
expect(consoleErrorSpy).toHaveBeenCalled();
Expand Down
24 changes: 12 additions & 12 deletions __tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { checkReadyState, executeHotjarCommand, initScript } from '../src/utils';
import type { WindowWithHotjar } from '../src/utils';
import { checkReadyState, executeContentsquareCommand, initScript } from '../src/utils';
import type { WindowWithContentsquare } from '../src/utils';

declare const window: WindowWithHotjar;
declare const window: WindowWithContentsquare;

const fakeHJ = jest.fn(() => {
return null;
Expand All @@ -14,7 +14,7 @@ describe('Utils', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should return false if Hotjar is not initiated', () => {
it('should return false if Contentsquare is not initiated', () => {
expect(checkReadyState()).toBe(false);
});

Expand All @@ -39,7 +39,7 @@ describe('Utils', () => {
initScript(12345, 1);
expect(document.head.appendChild).toHaveBeenCalledWith(
expect.objectContaining({
id: 'hotjar-init-script',
id: 'contentsquare-init-script',
crossOrigin: 'anonymous',
innerText: expect.stringMatching(/(?=.*hjdebug:false)(?=.*12345).*/i),
}),
Expand All @@ -52,7 +52,7 @@ describe('Utils', () => {
initScript(12345, 1, { debug: true });
expect(document.head.appendChild).toHaveBeenCalledWith(
expect.objectContaining({
id: 'hotjar-init-script',
id: 'contentsquare-init-script',
crossOrigin: 'anonymous',
innerText: expect.stringMatching(/(?=.*hjdebug:true)(?=.*12345).*/i),
}),
Expand All @@ -65,26 +65,26 @@ describe('Utils', () => {
});
expect(() => {
initScript(12345, 1);
}).toThrow('Failed to initialize Hotjar tracking script.');
}).toThrow('Failed to initialize Contentsquare tracking script.');
});
it('should throw if window.hj does not exist after the append', () => {
expect(() => {
initScript(12345, 1);
}).toThrow('Failed to initialize Hotjar tracking script.');
}).toThrow('Failed to initialize Contentsquare tracking script.');
});
});

describe('executeHotjarCommand', () => {
describe('executeContentsquareCommand', () => {
it('should execute window.hj command', () => {
window.hj = fakeHJ;
executeHotjarCommand('stateChange', 'my/new/url');
executeContentsquareCommand('stateChange', 'my/new/url');
expect(window.hj).toHaveBeenCalledWith('stateChange', 'my/new/url');
window.hj = undefined;
});
it('should throw if window.hj does not exist', () => {
expect(() => {
executeHotjarCommand('stateChange', 'my/new/url');
}).toThrow('Hotjar is not available, make sure init has been called.');
executeContentsquareCommand('stateChange', 'my/new/url');
}).toThrow('Contentsquare is not available, make sure init has been called.');
});
});
});
Loading

0 comments on commit 1526200

Please sign in to comment.