• Stars
    star
    505
  • Rank 87,373 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated almost 7 years ago

Reviews

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

Repository Details

Unobtrusive event emitter API for Google Universal Analytics event tracking

flare.js Build Status

flare.js, a <1KB unobtrusive event emitter API for Google Universal Analytics. With flare you can easily bind event JSON to a data-* attribute, or use flare.emit() to fire flares directly. Flare automatically calls ga('send') and constructs other properties (and arguments order) so you don't communicate with ga() directly. IE8+.

Remember to drop in Google Analytics beforehand! See docs for more.

Initialisation

Simply call flare.init() and go ahead and use data attributes, or the JavaScript API.

As data-* attribute

Pass in a JSON Object to data-flare to bind your event descriptors. Flare binds a click event unless a custom event is specified using data-flare-event="":

<!-- defaults to `click` -->
<a href="/promotions" data-flare='{
  "category": "KPI sections",
  "action": "click",
  "label": "Visit the promotions",
  "value": 4
}'>Click me</a>

<!-- uses `mouseover` -->
<a href="/promotions" data-flare-event="mouseover" data-flare='{
  "category": "KPI sections",
  "action": "mouseover",
  "label": "Visit the promotions",
  "value": 4
}'>Click me</a>

The data-flare-event gets passed into addEventListener and attachEvent, so ensure the event is valid.

As flare parses JSON from the data-* attribute, you can of course use some of the custom Google Universal Analytics properties such as { 'page': '/my-new-page' } and { 'nonInteraction': 1 }:

<a href="/promotions" data-flare='{
  "category": "KPI sections",
  "action": "click",
  "label": "Visit the promotions",
  "value": {
    "page": "/my-new-page"
  }
}'>Click me</a>

flare.emit()

Emit a custom flare to send to Google Universal Analytics:

flare.emit({
  category: "KPI sections",
  action: "click",
  label: "Visit the promotions",
  value: 4
});

Then use within your own logic:

<a href="/promotions" class="promotions">Click me</a>
<script>
document
  .querySelector('.promotions')
  .addEventListener('click', function () {
    // emit a flare
    flare.emit({
      category: "KPI sections",
      action: "click",
      label: "Visit the promotions",
      value: 4
    });
  }, false);
</script>

Installing with npm

npm install flare.js

Installing with Bower

bower install flare

Manual installation

Ensure you're using the files from the dist directory (contains compiled production-ready code). Ensure you place the script before the closing </body> tag.

<body>
  <!-- html above -->
  <script src="dist/flare.js"></script>
  <script>
  // flare module available
  </script>
</body>

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.

Release history

  • 1.0.0
    • Initial release

More Repositories

1

angularjs-styleguide

AngularJS styleguide for teams
5,965
star
2

echo

Lazy-loading images with data-* attributes
JavaScript
3,723
star
3

fireshell

Fiercely quick front-end boilerplate and workflows, HTML5, Grunt, Sass.
JavaScript
1,519
star
4

angular-1-5-components-app

A Contacts Manager application built on Angular 1.5 components, ui-router 1.0.0, Firebase.
JavaScript
573
star
5

angular-pizza-creator

Source code for Angular advanced Form APIs pizza builder
TypeScript
450
star
6

fluidvids

Fluid width (responsive) videos module, 1KB, custom players, dynamic elements/XHR support.
JavaScript
415
star
7

angular-dynamic-forms

Configurable Reactive Forms in Angular with dynamic components
TypeScript
317
star
8

angular-architecture

Angular architecture guide for teams.
262
star
9

apollo

Standalone cross-browser DOM class manipulation module
JavaScript
250
star
10

angular-component

Fully featured .component() polyfill for Angular v1.3+
JavaScript
191
star
11

reactive-pizza

Angular v4.1.1 - Reactive Forms, Observables, Component Architecture. Pizza. 🍕
TypeScript
180
star
12

axis

Simple JavaScript type checking module. Returns a Boolean for each type check.
JavaScript
179
star
13

superbox

Superbox, the lightbox, reimagined
JavaScript
125
star
14

flaunt-js

Flaunt JS, stylish responsive navigations with nested click to reveal
CSS
89
star
15

linkjuice

Automatically wraps and creates anchor links for <h1-h6> headings
JavaScript
88
star
16

foreach

forEach implementation for Objects/NodeLists/Arrays, automatic type loops and context options
JavaScript
81
star
17

lunar

SVG class module for has/add/remove/toggleClass
JavaScript
78
star
18

stratos

Object manipulation module, simplified extends, keys, add/remove methods and more.
JavaScript
72
star
19

interpolate

Micro templating engine, maps Object property values to a String template
JavaScript
56
star
20

console.loge

Doge-driven debugging. Such console, many logs. Wow.
JavaScript
47
star
21

jbar

jBar, the lightweight jQuery notification banner.
CSS
32
star
22

superfast-angular-2

A super simple setup for Angular 2 to prototype or play around. Components, TypeScript and Routing.
JavaScript
32
star
23

gulp-oss

My Gulp.js boilerplate for creating new JavaScript projects
JavaScript
28
star
24

NoFi

No WiFi, detecting offline states with HTML5
JavaScript
25
star
25

switch-messages

switchMessages for Angular 1.2+, partial functionality from Angular 1.3+ "ngMessages"
JavaScript
24
star
26

fluidvids-react

React.js implementation of fluidvids.js
JavaScript
23
star
27

track-digests

A simple Directive to track $digest counts
JavaScript
21
star
28

psswrd

Show/hide toggling for password inputs.
JavaScript
21
star
29

ac-store

Simple Redux Store
TypeScript
19
star
30

angular-connect-2016

Final code for AngularConnect Angular 1 & 2 demos.
HTML
18
star
31

suave

Re-engineering the HTML5 <video> tag for semantics and modularity.
JavaScript
16
star
32

ac-boilerplate

TypeScript
15
star
33

mapify

Map iteration for Arrays and Objects
JavaScript
14
star
34

fluidvids-polymer

Web Component for fluidvids.js built with Polymer
14
star
35

ngrx-workshop

JavaScript
12
star
36

data-tabs

Simple HTML5 data-* jQuery tabs. Markup free and relative to their container for ultimate re-use.
12
star
37

workspaces-grunt

Using Grunt and Chrome Workspaces for in-browser development
JavaScript
10
star
38

fowa2014

FOWA 2014 workshop
CSS
7
star
39

ngWorkshop2015

[this is really old, wouldn't bother using it] Falsy Values AngularJS Workshop 2015
JavaScript
5
star
40

babel-private-properties-methods-classes

🔥 Babel + ESLint + Private Properties and Methods in Classes
5
star
41

imgShufflr

jQuery random image shufflr, inline img and background CSS
5
star
42

ngbe-2016

Source code moved here: https://github.com/toddmotto/angular-pizza-creator
5
star
43

selectnav

JavaScript select navigation for responsive projects
JavaScript
4
star
44

fitdevcomments

3
star
45

aot-loader

[BETA/Work In Progress] Ahead-of-Time Compiler for Webpack.
JavaScript
3
star
46

web-platform-angular-2

HTML
3
star
47

required-fallback

A robust HTML5 'required' attribute fallback, client-side jQuery script.
3
star
48

bounceThis

jQuery plugin that mimics CSS3 keyframes animations of bouncing headers
JavaScript
2
star
49

kendo-html-editor

HTML
2
star
50

fowd

CSS
1
star