Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: electerious
custom: ['https://paypal.me/electerious', 'https://www.buymeacoffee.com/electerious']
custom: ['https://paypal.me/electerious', 'https://www.buymeacoffee.com/electerious']
65 changes: 0 additions & 65 deletions .github/workflows/build.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

permissions:
contents: read

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: 'Test'
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
matrix:
node-version: [20.x, 22.x, 24.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v5

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}

- run: npm ci

- run: npm test
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Changed

- Requires Node.js 18 or newer
- Requires React 17 or newer
- Requires Node.js 20 or newer

## [3.1.0] - 2024-06-13

Expand Down Expand Up @@ -72,4 +73,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Added

- Everything
- Everything
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# use-ackee

![Build](https://github.com/electerious/use-ackee/workflows/Build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/electerious/use-ackee/badge.svg?branch=master)](https://coveralls.io/github/electerious/use-ackee?branch=master)
[![Test](https://github.com/electerious/use-ackee/actions/workflows/test.yml/badge.svg)](https://github.com/electerious/use-ackee/actions/workflows/test.yml)

Use [Ackee](https://github.com/electerious/Ackee) in React.

Expand All @@ -10,25 +10,27 @@ Use [Ackee](https://github.com/electerious/Ackee) in React.
npm install use-ackee
```

*or*

```
yarn add use-ackee
```

## Usage

Import and call `use-ackee` in a component responsible for the routing or inside your routes. Make sure that only one `use-ackee` hook is actively rendered to avoid redundant records.

```js
useAckee('/current/path', {
server: 'https://example.com',
domainId: 'hd11f820-68a1-11e6-8047-79c0c2d9bce0'
}, {
detailed: false,
ignoreLocalhost: true,
ignoreOwnVisits: true
})
import useAckee from 'use-ackee'
```

```js
useAckee(
'/current/path',
{
server: 'https://example.com',
domainId: 'hd11f820-68a1-11e6-8047-79c0c2d9bce0',
},
{
detailed: false,
ignoreLocalhost: true,
ignoreOwnVisits: true,
},
)
```

Ackee will create a new record every time the `pathname` changes. An undefined or empty `pathname` will be skipped. Use `/` for the root instead.
Expand All @@ -39,10 +41,10 @@ This hook is a no-op on the server for safe usage during server-side rendering.

### Parameters

- `pathname` `{?String}` Current path.
- `environment` `{Object}` An object that contains details about your [Ackee](https://github.com/electerious/Ackee) installation. The `server` property must not end with a slash.
- `opts` `{?Object}` An object of [Ackee options](https://github.com/electerious/ackee-tracker#options).
- `pathname` `{?string}` Current path.
- `environment` `{object}` An object that contains details about your [Ackee](https://github.com/electerious/Ackee) installation. The `server` property must not end with a slash.
- `opts` `{?object}` An object of [Ackee options](https://github.com/electerious/ackee-tracker#options).

## Examples

- [React Router](demos/react-router/README.md)
- [React Router](demos/react-router/README.md)
6 changes: 3 additions & 3 deletions demos/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"start": "react-scripts start",
"test": "react-scripts test"
},
"browserslist": {
"production": [
Expand Down
14 changes: 6 additions & 8 deletions demos/react-router/src/About.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react'

const About = () => {
return (
<div>
<h2>About</h2>
</div>
)
return (
<div>
<h2>About</h2>
</div>
)
}

export default About
export default About
13 changes: 6 additions & 7 deletions demos/react-router/src/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from 'react'
import { BrowserRouter as Router } from 'react-router-dom'

import Content from './Content'

const App = () => {
return (
<Router>
<Content />
</Router>
)
return (
<Router>
<Content />
</Router>
)
}

export default App
export default App
87 changes: 45 additions & 42 deletions demos/react-router/src/Content.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
import React from 'react'
import { Switch, Route, Link, useLocation } from 'react-router-dom'
import { Link, Route, Switch, useLocation } from 'react-router-dom'

import useAckee from 'use-ackee'

import Home from './Home'
import About from './About'
import Dashboard from './Dashboard'
import Home from './Home'

const Content = () => {
const location = useLocation()

useAckee(location.pathname, {
server: 'https://example.com',
domainId: 'hd11f820-68a1-11e6-8047-79c0c2d9bce0',
}, {
ignoreLocalhost: false,
})

return (
<div>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/dashboard">Dashboard</Link>
</li>
</ul>

<hr />

<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/about">
<About />
</Route>
<Route path="/dashboard">
<Dashboard />
</Route>
</Switch>
</div>
)
const location = useLocation()

useAckee(
location.pathname,
{
server: 'https://example.com',
domainId: 'hd11f820-68a1-11e6-8047-79c0c2d9bce0',
},
{
ignoreLocalhost: false,
},
)

return (
<div>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/dashboard">Dashboard</Link>
</li>
</ul>

<hr />

<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/about">
<About />
</Route>
<Route path="/dashboard">
<Dashboard />
</Route>
</Switch>
</div>
)
}

export default Content
export default Content
14 changes: 6 additions & 8 deletions demos/react-router/src/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react'

const Dashboard = () => {
return (
<div>
<h2>Dashboard</h2>
</div>
)
return (
<div>
<h2>Dashboard</h2>
</div>
)
}

export default Dashboard
export default Dashboard
14 changes: 6 additions & 8 deletions demos/react-router/src/Home.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react'

const Home = () => {
return (
<div>
<h2>Home</h2>
</div>
)
return (
<div>
<h2>Home</h2>
</div>
)
}

export default Home
export default Home
3 changes: 1 addition & 2 deletions demos/react-router/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import ReactDOM from 'react-dom'

import App from './App'

ReactDOM.render(<App />, document.getElementById('root'))
ReactDOM.render(<App />, document.getElementById('root'))
Loading
Loading