Created
February 22, 2017 15:40
-
-
Save mbaez/a56ba7dfaee5cc6bac575b29e6f547e1 to your computer and use it in GitHub Desktop.
Integración de un SPA (angular) con google analytics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definición del módulo | |
*/ | |
var app = angular.module("demoApp",[/*Dependencias*/]); | |
/** | |
* Configuracin de las rutas. | |
*/ | |
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { | |
$routeProvider | |
/* TODO RUTAS*/ | |
.otherwise({redirectTo: '/'}); | |
/*Some code*/ | |
}]); | |
/** | |
* Como es un SPA (Single Page Aplication) no se puede utilizar el codigo | |
* de seguimiento en el index.html. Este solo se carga una vez y la demás cargas | |
* se realizan con AJAX. Si se desea trackear las visiatas a todas las páginas se debe | |
* hacer bind del evento "route change" y enviar un "page-view" para cada ruta nueva. | |
*/ | |
app.run(['$rootScope', '$location', '$window', function ($rootScope, $location, $window) { | |
// initialise google analytics | |
$window.ga('create', 'UA-XXXXXXXX-X', 'auto'); | |
// track pageview on state change | |
$rootScope.$on('$routeChangeStart', function (event) { | |
$window.ga('send', 'pageview', $location.path()); | |
}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amigo y para react