• Stars
    star
    190
  • Rank 197,302 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Transfer data to Ackee.
ackee-tracker logo

ackee-tracker

Donate via PayPal

A script that interacts with the API of Ackee. Should be included on your site to track data.


Ackee tracker code

πŸš€ Installation

We recommend loading ackee-tracker from your Ackee instance. This ensures that the script is always in sync with your installation. The script is served as tracker.js or as a name of your choice.

<script async src="https://ackee.example.com/tracker.js" data-ackee-server="https://ackee.example.com" data-ackee-domain-id="hd11f820-68a1-11e6-8047-79c0c2d9bce0"></script>

It's also possible to install ackee-tracker as a module via npm or yarn.

npm install ackee-tracker
yarn add ackee-tracker

πŸ€— Usage

Type Usage Best for Records (Views) Actions (Events)
Automatically Via script tag Simple sites βœ… ⛔️
Manually Via script tag and code Advanced sites βœ… βœ…
Programmatic Via module Modern sites with build tools βœ… βœ…

Automatically

The easiest way to send data to your Ackee server is by including the script along with the required attributes. Ackee will now track each page visit automatically.

This approach is perfect for static sites. It tracks a visit whenever a user visits the site or navigates to a new page. Websites with client-side routing however should consider to use any of the other approaches as this one would only track the initial page.

<script async src="dist/ackee-tracker.min.js" data-ackee-server="https://ackee.example.com" data-ackee-domain-id="hd11f820-68a1-11e6-8047-79c0c2d9bce0"></script>

It's also possible to customize Ackee using the data-ackee-opts attribute.

<script async src="dist/ackee-tracker.min.js" data-ackee-server="https://ackee.example.com" data-ackee-domain-id="hd11f820-68a1-11e6-8047-79c0c2d9bce0" data-ackee-opts='{ "ignoreLocalhost": true }'></script>

Manually

Include the JS-file at the end of your body and start tracking page visits by calling create manually.

This approach is perfect for sites without a build system. It gives you more control than the automatic solution, but still allows you to use ackee-tracker without a package manager or JS bundler.

<script src="dist/ackee-tracker.min.js"></script>

<script>
	ackeeTracker.create('https://ackee.example.com').record('hd11f820-68a1-11e6-8047-79c0c2d9bce0')
</script>

Programmatic

Use ackee-tracker as a module and start tracking page visits by calling create.

This approach is perfect if your site uses client-side routing or changes content without reloading the site. It allows you to call Ackee whenever you need.

Example:

const ackeeTracker = require('ackee-tracker')

ackeeTracker.create('https://ackee.example.com').record('hd11f820-68a1-11e6-8047-79c0c2d9bce0')
import * as ackeeTracker from 'ackee-tracker'

ackeeTracker.create('https://ackee.example.com').record('hd11f820-68a1-11e6-8047-79c0c2d9bce0')

βš™οΈ API

.detect()

Looks for an element with Ackee attributes, creates an instance and starts tracking.

This function runs automatically in a browser environment and fails silently when it can't find a suitable element. You usually don't need to call this function.

Example:

<div hidden data-ackee-server="https://ackee.example.com" data-ackee-domain-id="hd11f820-68a1-11e6-8047-79c0c2d9bce0"></div>
ackeeTracker.detect()

.create(server, options)

Creates a new ackee-tracker instance.

Be sure to assign your instance to a variable. Tracking a visit or event is only possible with an instance.

Examples:

const instance = ackeeTracker.create('https://ackee.example.com')
const instance = ackeeTracker.create('https://ackee.example.com', {
	detailed: false,
	ignoreLocalhost: true
})

Parameters:

  • server {String} An URL that points to your Ackee installation. The server property must not end with a slash.
  • options {?Object} An object of options.

Returns:

  • {Object} The created instance.

.attributes()

Gathers and returns all platform-, screen- and user-related information.

Examples:

const attributes = ackeeTracker.attributes()
const attributes = ackeeTracker.attributes(true)

Parameters:

  • detailed {Boolean} Include personal data.

Returns:

  • {Object} User-related information.

βš™οΈ Instance API

Each ackeeTracker instance is an object with functions you can use to track visits and events.

.record(domainId, attributes, callback)

Creates a new record on the server and updates the record constantly to track the duration of the visit.

Examples:

instance.record('hd11f820-68a1-11e6-8047-79c0c2d9bce0')
instance.record('hd11f820-68a1-11e6-8047-79c0c2d9bce0', {
	siteLocation: window.location.href,
	siteReferrer: document.referrer
})
instance.record('hd11f820-68a1-11e6-8047-79c0c2d9bce0', undefined, (recordId) => {
	console.log(`Created new record with id '${ recordId }'`)
})
const { stop } = instance.record('hd11f820-68a1-11e6-8047-79c0c2d9bce0')

// Manually stop updating the visit duration. The returned function should be used in
// single-page applications. Call the function when the user navigates to a new page
// before creating a new record.
stop()

Parameters:

  • domainId {String} Id of the domain.
  • attributes {?Object} Attributes that should be transferred to the server. Will be ackeeTracker.attributes() unless specified otherwise.
  • callback {?Function}({?String}) Function that executes once the record has been created. Receives the id of the new record.

Returns:

  • {Object} Object with a stop function. Call the returned function to stop updating the visit duration of the created record.

.updateRecord(recordId)

Updates a record constantly to track the duration of a visit. You usually don't need to call this function, because .record calls this function for you. It's however helpful when you want to continue tracking a record after a page reload or after a record has been stopped.

Updating attributes of an existing record isn't possible.

Examples:

instance.updateRecord('dfa929d3-bfbf-43f2-9234-ed646eb68767')
const { stop } = instance.updateRecord('dfa929d3-bfbf-43f2-9234-ed646eb68767')

// Manually stop updating the visit duration. The returned function should be used in
// single-page applications. Call the function when the user navigates to a new page
// before creating a new record.
stop()

Parameters:

  • recordId {String} Id of the record.

Returns:

  • {Object} Object with a stop function. Call the returned function to stop updating the visit duration.

.action(eventId, attributes, callback)

Creates a new action on the server to track an event.

Tipps:

  • key won't show up in the Ackee UI for every event type, but must be specified nevertheless
  • Use 1 as value to count how many times an event occurred or a price (e.g. 9.99) to see the sum of successful checkouts in a shop
  • Reset an existing value using null when the user canceled an event (e.g. removed an item from the checkout)

Examples:

instance.action('513a082c-2cd5-4939-b417-72da2fe1761d', {
	key: 'Checkout',
	value: 9.99
})
instance.action('1b6e20cb-7c7d-48ca-8cb6-958a55d7a9e3', {
	key: 'Subscription',
	value: 1
}, (actionId) => {
	console.log(`Created new action with id '${ actionId }'`)
})

Parameters:

  • eventId {String} Id of the event.
  • attributes {Object} Attributes that should be transferred to the server.
    • key {String} Key that will be used to group similar actions in the Ackee UI.
    • value {?Number} Positive float value that is added to all other numerical values of the key.
  • callback {?Function}({?String}) Function that executes once the action has been created. Receives the id of the new action.

.updateAction(actionId, attributes)

Updates an action on the server.

Examples:

instance.updateAction('7fe70f50-cb16-4e27-90ab-d6210296a4b7', {
	key: 'Checkout',
	value: '4.99'
})
instance.updateAction('24776c2b-c5d6-4fac-852a-067d086dc4af', {
	key: 'Subscription',
	value: null
})

Parameters:

  • actionId {String} Id of the action.
  • attributes {Object} Attributes that should be transferred to the server.
    • key {String} Key that will be used to group similar actions in the Ackee UI.
    • value {?Number} Positive float value that is added to all other numerical values of the key.

πŸ”§ Options

The option-object can include the following properties:

{
	/*
	 * Enable or disable tracking of personal data.
	 * We recommend to ask the user for permission before turning this option on.
	 */
	detailed: false,
	/*
	 * Enable or disable tracking when on localhost.
	 */
	ignoreLocalhost: true,
	/*
	 * Enable or disable the tracking of your own visits.
	 * This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
	 * Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
	 */
	ignoreOwnVisits: true
}

Miscellaneous

Donate

I am working hard on continuously developing and maintaining Ackee. Please consider making a donation to keep the project going strong and me motivated.

Links

More Repositories

1

Lychee

A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.
PHP
6,312
star
2

Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
JavaScript
4,121
star
3

basicScroll

Standalone parallax scrolling for mobile and desktop with CSS variables.
JavaScript
3,633
star
4

formbase

Better default styles for common input elements.
SCSS
567
star
5

basicLightbox

The lightest lightbox ever made.
JavaScript
532
star
6

basicModal

Easy-to-use dialog system for modern web-apps.
JavaScript
283
star
7

basicContext

Easy-to-use context-menu for your website or webapp.
JavaScript
168
star
8

Rosid

Just-in-time development server and static site generator.
JavaScript
143
star
9

nice-try

Tries to execute a function and discards any error that occurs.
JavaScript
66
star
10

basicGrid

A Foundation-like grid system based on the flex display property.
SCSS
56
star
11

basicSlider

A slider in its purest form.
JavaScript
33
star
12

scrollSnap

Section-based scrolling for your site.
JavaScript
27
star
13

fsify

Convert an array of objects into a persistent or temporary directory structure.
JavaScript
26
star
14

Skeleton-Components

A front-end Malvid template build upon Rosid.
CSS
24
star
15

use-ackee

Use Ackee in React.
JavaScript
23
star
16

basicRotate

Rotate throw a set of 360 degree images using your mouse or finger.
JavaScript
20
star
17

ackee-bitbar

Ackee stats in your macOS menu bar.
JavaScript
16
star
18

ackee-lighthouse

Send Lighthouse reports to Ackee.
JavaScript
13
star
19

Skeleton-EJS

A front-end template build upon Rosid.
CSS
13
star
20

basicPlaceholder

Easy-to-use persistent placeholders for input fields.
JavaScript
10
star
21

basicNotification

Easy-to-use notification-system for your website or webapp.
CoffeeScript
9
star
22

basicPaginate

Paginate a NodeList like there's no tomorrow.
JavaScript
9
star
23

limit-number

Limit a number between a min and max value.
JavaScript
7
star
24

zbarimg

Scan photos using ZBar in Node.js.
CoffeeScript
6
star
25

dribbble-2x

Safari extension for Dribbble, which always shows the @2x version.
JavaScript
6
star
26

rosid-handler-sass

Load SCSS and transform to CSS, add vendor prefixes and minify.
JavaScript
6
star
27

basicTasks

A collection of gulp-tasks used in personal projects.
JavaScript
5
star
28

rosid-handler-twig

Load Twig templates and render them.
JavaScript
5
star
29

Feedboard

Design your feed.
JavaScript
5
star
30

Skeleton-NJK

A front-end template build upon Rosid.
CSS
5
star
31

key-value-replace

Replace key/value pairs in a string.
JavaScript
5
star
32

rosid-handler-ejs

Load EJS templates and render them.
JavaScript
5
star
33

lychee-watermark

Adds a second watermarked photo when uploading images to Lychee.
PHP
5
star
34

require-data

Extracts data out of multiple file types.
JavaScript
5
star
35

lychee-redirect

Redirect from an album-name to a Lychee-album.
PHP
5
star
36

rename-extension

Changes the the extension of a given filename or path.
JavaScript
5
star
37

rosid-handler-njk

Load Nunjucks templates and render them.
JavaScript
4
star
38

rosid-handler-js

Load, transform, bundle and compress JS.
JavaScript
4
star
39

basicFit

Turn elements on your site into a responsive unified grid.
CoffeeScript
4
star
40

rosid-handler-node

Load JS and transform to HTML.
JavaScript
3
star
41

count-between

Counts up and down between two numbers.
JavaScript
3
star
42

ausgabe

Tiny logger with zero defaults.
JavaScript
3
star
43

modulizer

Wrap this snippets around your code to support CommonJS, AMD and non-module-definitions.
JavaScript
3
star
44

eslint-config

ESLint configuration for my personal projects.
JavaScript
2
star
45

pdfconcat

Concat multiple pdfs using pdfunite in Node.js.
CoffeeScript
2
star
46

continuous-stealthy-require

Requires a fresh, uncached module without causing a memory leak.
JavaScript
2
star
47

ackee-faker

Fills Ackee with fake data.
JavaScript
2
star
48

Ackee-Netlify-Test-Instance

JavaScript
1
star
49

rosid-handler-js-next

Load, transform, bundle and compress modern JS.
JavaScript
1
star
50

Skeleton-React

A front-end template build upon Rosid.
JavaScript
1
star
51

vh-variable

TypeScript
1
star