mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-01 16:34:14 -04:00
Add Discourse-Track-View
header to XHR when transitioning
This commit is contained in:
parent
4e64d16a47
commit
a852f6c56f
3 changed files with 28 additions and 2 deletions
app/assets/javascripts/discourse
|
@ -5,7 +5,14 @@ export default {
|
||||||
name: "page-tracking",
|
name: "page-tracking",
|
||||||
after: 'register-discourse-location',
|
after: 'register-discourse-location',
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function(container) {
|
||||||
|
|
||||||
|
// Tell our AJAX system to track a page transition
|
||||||
|
var router = container.lookup('router:main');
|
||||||
|
router.on('willTransition', function() {
|
||||||
|
Discourse.viewTrackingRequired();
|
||||||
|
});
|
||||||
|
|
||||||
var pageTracker = Discourse.PageTracker.current();
|
var pageTracker = Discourse.PageTracker.current();
|
||||||
pageTracker.start();
|
pageTracker.start();
|
||||||
|
|
||||||
|
@ -19,7 +26,6 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Also use Universal Analytics if it is present
|
// Also use Universal Analytics if it is present
|
||||||
if (typeof window.ga !== 'undefined') {
|
if (typeof window.ga !== 'undefined') {
|
||||||
pageTracker.on('change', function(url, title) {
|
pageTracker.on('change', function(url, title) {
|
||||||
|
|
|
@ -7,8 +7,15 @@
|
||||||
@namespace Discourse
|
@namespace Discourse
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
var _trackView = false;
|
||||||
|
|
||||||
Discourse.Ajax = Em.Mixin.create({
|
Discourse.Ajax = Em.Mixin.create({
|
||||||
|
|
||||||
|
viewTrackingRequired: function() {
|
||||||
|
_trackView = true;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
|
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
|
||||||
for performance reasons. Also automatically adjusts the URL to support installs
|
for performance reasons. Also automatically adjusts the URL to support installs
|
||||||
|
@ -42,6 +49,11 @@ Discourse.Ajax = Em.Mixin.create({
|
||||||
|
|
||||||
var performAjax = function(resolve, reject) {
|
var performAjax = function(resolve, reject) {
|
||||||
|
|
||||||
|
if (_trackView) {
|
||||||
|
_trackView = false;
|
||||||
|
args.headers = { 'Discourse-Track-View': true };
|
||||||
|
}
|
||||||
|
|
||||||
args.success = function(xhr) {
|
args.success = function(xhr) {
|
||||||
Ember.run(null, resolve, xhr);
|
Ember.run(null, resolve, xhr);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,14 @@ Discourse.Route = Ember.Route.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
|
// Ember doesn't provider a router `willTransition` event so let's make one
|
||||||
|
willTransition: function() {
|
||||||
|
var router = this.container.lookup('router:main');
|
||||||
|
Ember.run.once(router, router.trigger, 'willTransition');
|
||||||
|
return this._super();
|
||||||
|
},
|
||||||
|
|
||||||
_collectTitleTokens: function(tokens) {
|
_collectTitleTokens: function(tokens) {
|
||||||
// If there's a title token method, call it and get the token
|
// If there's a title token method, call it and get the token
|
||||||
if (this.titleToken) {
|
if (this.titleToken) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue