• Stars
    star
    633
  • Rank 68,533 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 8 years ago

Reviews

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

Repository Details

The solution to tracking page views and events in a SPA with AngularJS

#Angularytics

PayPayl donate button Donate on Gittip

Angularytics is the solution to tracking PageViews and Events on your Single Page App.

All analytics frameworks are based on browser refreshes to track page views. I've created this service wrapper so that we can track page views in our WebApp without a page refresh and without too much configuration.

Main Features

This are Angularytics main features:

  • It automatically tracks a new page view with all of the connected providers (For now Google Analytics and console.log) once you change the URL in your SPA
  • It gives you the ability to track events either by calling the Angularytics service or by using the trackEvent filter.

#How do I add this to my project?

You can download this by:

#Prerequisites

Angularytics depends on AngularJS.

You need to add the needed Analytics code (Google Analytics) in your app. I thought of adding this in the service, but if you just add it in the body, it'd load MUCH faster than if we loaded this in the init. If everybody wants to move this to the service's init, then please submit an issue.

#Starter Guide

TL;DR Basic configuration on your app.

This is the quick configuration to bootstrap all. Read the rest of the documentation for further configuration and understanding. After doing this, Angularytics will automatically track all of the page views in the app for you.

angular.module('sample-app', ['angularytics'])
  .config(function(AngularyticsProvider) {
    AngularyticsProvider.setEventHandlers(['Console', 'GoogleUniversal']);
  }).run(function(Angularytics) {
    Angularytics.init();
  });

Tracking Page Views

This is easy :). You don't need to do anything. By configuring Angularytics with your app like in the step before, all pages will start being tracked.

If you wish to disable this for whatever reason, you can use:

.config(function(AngularyticsProvider) {
  AngularyticsProvider.setEventHandlers(['Console', 'GoogleUniversal']);
  AngularyticsProvider.disablePageViewTracking();
})

Tracking events

The trackEvent function in service and filter has the same parameters in the same order as Google Analytics. Click here to check the Google Analytics documentation. There're 2 ways of tracking events. Either using Angularytics service, or using the filter.

Using the filter

This is the most common way of tracking events. Suppose that you have a button which calls some function on your scope and you want to track when that button is clicked. This is the example:

<input type="submit" ng-click="doSomething() | trackEvent:'Home Category':'Button clicked'" />

Using the service

You just need to inject the service and call the trackEvent function.

Let's see an example:

angular.controller('MainCtrl', function(Angularytics, $scope) {
    $scope.click = function() {
        Angularytics.trackEvent("Home Category", "Button clicked");
    }
});

Event Handlers (Available providers)

There are 3 event handlers: Console, Google, and GoogleUniversal. The last one of this uses ga instead of _gaq.

  • Console logs all page views and events.
  • Google tracks all page views and events using Google Analytics.

Adding your own event handler

You can add your own event handler in 3 easy steps:

Create your service.

You need to create a service with the following name format: Angularytics[EventHandlerName]Handler. For example: AngularyticsKissmetricsHandler.

This service must have the following methods and signatures:

  • trackPageView(url): Tracks a page view to the given URL
  • trackEvent(category, action, opt_label, opt_value, opt_noninteraction): Tracks a new event with the given parameters
  • trackTiming(category, variable, value, opt_label): Tracks user timings with the given parameters

Use this service by changing the AngularyticsProvider

Use this newly created service by setting the name in the AngularyticsProvider. For example:

// Considering the service is named AngularyticsKissmetricsHandler
AngularyticsProvider.setEventHandlers(['Console', 'Kissmetrics']);

Have fun using it

This is easy, right?

Releases Notes

Click here to see Releases Notes

License

The MIT License

Copyright (c) 2013 Martin Gontovnikas http://www.gon.to/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge

More Repositories

1

restangular

AngularJS service to handle Rest API Restful Resources properly and easily
JavaScript
7,881
star
2

mgo-mousetrap

Handling keyboard interaction on an Angular app: An Angular Mousetrap wrapper
JavaScript
144
star
3

factory_pal

A Scala framework for creating objects as test data. Say no to Mocks
Scala
98
star
4

mgo-ui-router-goto

A directive for ui-router that lets you link to states instead of URLs
JavaScript
52
star
5

meaner-seed

A better organised, more complete and updated MEAN seed
JavaScript
50
star
6

gulp-browserify-library-seed

This is a seed (kickstarter) project to create your own library which will use Browserify and Gulp
JavaScript
35
star
7

slick-play2-example

slick-play2-example
Scala
27
star
8

angular-ux

A library that helps you create live, navigable prototypes with the help of AngularJS but without having to learn how to code ;). DESIGNERS, I'm looking at you!
JavaScript
22
star
9

jpa-passive-logging-example

A JPA changes (Create, Modify and Delete) model logger that does this passively.
Java
16
star
10

heroku-static-file-server

Serve static files in Heroku
16
star
11

front-is-the-new-back

The front is the new back talk: Introducing Webtasks
CSS
11
star
12

angular-101-from-n00b-to-ngExpert

AngularJS Training with excercises
JavaScript
9
star
13

angular-security-workshop

Security workshop with Angular
JavaScript
8
star
14

restangular-talk

Restangular talk
HTML
8
star
15

a-token-walks-into-a-SPA

A token enters into a SPA: Angular 2 Authentication talk
CSS
6
star
16

sublime-config

sublime-config
Python
6
star
17

reactive-frontend-oscon

Reactive Frontend Oscon Slides
JavaScript
6
star
18

angello-angularjs-in-action

NodeJS Express app for Angello sample in AngularJS in Action
JavaScript
5
star
19

instagram-user-hash-searcher

Searcher for pictures for a particular user that contain a particular hashtag
JavaScript
4
star
20

specs

Specifications for building stuff
4
star
21

restangular-plugins

Plugins for Restangular to make your life easier.
4
star
22

reactive-all-the-things-talk

Reactive All The Things talk in ngConf
JavaScript
4
star
23

how-to-create-good-documentation-talk

"Stop wasting developers time! How to create good documentation?" TaΓ±l
CSS
4
star
24

angular2-the-new-horizon

Intro talk to Angular 2
CSS
3
star
25

angularjs-good-practices

AngularJS Good Practices
JavaScript
3
star
26

play-framework-2-video-course

Play Framework Video Course for Packt Publishing
CSS
3
star
27

talk-starter

A starter project for any future talks :)
CSS
3
star
28

a-token-walks-into-a-spa-rosario

A token walks into a SPA Rosario
CSS
2
star
29

gon.to-old

The blog & website for gon.to
JavaScript
2
star
30

tournament

Torneo
Ruby
2
star
31

are-your-SPAs-safe-talk

Talk about security on Single Page Apps
HTML
2
star
32

restangular-talk-with-image-right

Restangular talk with rights for images
JavaScript
2
star
33

death-to-cookies-cascadia

Death to cookies: Long live JSON Web Tokens talk at Cascadia
CSS
2
star
34

teammates

iOS App for Soccer playing
Swift
1
star
35

auth0-python-flaskapi-sample

Auth0 + Python + Flas API Seed
Python
1
star
36

a-comerla

A Comerla
1
star
37

tessel-lock

Tessel Lock
JavaScript
1
star
38

mgonto.github.com

Github pages for mgonto
1
star
39

learning-html

Learning HTML with @tyny
JavaScript
1
star
40

prototyping-with-angularjs

Example of Prototyping with AngularJS
HTML
1
star
41

angularjs-todo-frontend-talk

TODO app made with AngularJS for the FrontEnd quick intro (40 min) talk
JavaScript
1
star
42

videolibrary

A library for your videos
Scala
1
star
43

reactive-frontend-talk

Learn what Reactive Programming is and how to use it on Frontend apps
JavaScript
1
star