@financial-times/o-tracking
Advanced tools
Comparing version 3.1.3 to 3.1.4
@@ -97,3 +97,3 @@ import { get as getSetting } from "./settings.js"; | ||
var url = 'https://spoor-api.ft.com/px.gif'; | ||
var url = 'https://spoor-api.ft.com/ingest'; | ||
@@ -100,0 +100,0 @@ if (request && request.category && request.action) { |
@@ -6,2 +6,3 @@ import Delegate from "ftdomdelegate"; | ||
import { getTrace } from "../../libs/get-trace.js"; | ||
import { Queue } from "../core/queue.js"; | ||
var delegate; | ||
@@ -71,5 +72,16 @@ var eventPropertiesToCollect = ["ctrlKey", "altKey", "shiftKey", "metaKey"]; // Get properties for the event (as opposed to properties of the clicked element) | ||
delegate = delegate || new Delegate(document.body); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); // Fire all click events that were stored in the old queue used by o-tracking v2 | ||
var clickQueue = new Queue('clicks'); | ||
sendAllEventsFromQueue(clickQueue); | ||
}; | ||
function sendAllEventsFromQueue(queue) { | ||
var nextLink = queue.shift(); | ||
if (nextLink) { | ||
core.track(nextLink, () => sendAllEventsFromQueue(queue)); | ||
} | ||
} | ||
var click = { | ||
@@ -76,0 +88,0 @@ init |
@@ -110,3 +110,3 @@ "use strict"; | ||
var url = 'https://spoor-api.ft.com/px.gif'; | ||
var url = 'https://spoor-api.ft.com/ingest'; | ||
@@ -113,0 +113,0 @@ if (request && request.category && request.action) { |
@@ -18,2 +18,4 @@ "use strict"; | ||
var _queue = require("../core/queue.js"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -86,5 +88,16 @@ | ||
delegate = delegate || new _ftdomdelegate.default(document.body); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); // Fire all click events that were stored in the old queue used by o-tracking v2 | ||
var clickQueue = new _queue.Queue('clicks'); | ||
sendAllEventsFromQueue(clickQueue); | ||
}; | ||
function sendAllEventsFromQueue(queue) { | ||
var nextLink = queue.shift(); | ||
if (nextLink) { | ||
_core.default.track(nextLink, () => sendAllEventsFromQueue(queue)); | ||
} | ||
} | ||
var click = { | ||
@@ -91,0 +104,0 @@ init |
@@ -16,3 +16,3 @@ { | ||
"name": "@financial-times/o-tracking", | ||
"version": "3.1.3", | ||
"version": "3.1.4", | ||
"description": "Origami module for FT tracking.", | ||
@@ -19,0 +19,0 @@ "dependencies": { |
@@ -99,3 +99,3 @@ import {get as getSetting} from './settings.js'; | ||
*/ | ||
let url = 'https://spoor-api.ft.com/px.gif'; | ||
let url = 'https://spoor-api.ft.com/ingest'; | ||
@@ -102,0 +102,0 @@ if (request && request.category && request.action) { |
@@ -6,2 +6,3 @@ import Delegate from 'ftdomdelegate'; | ||
import {getTrace} from '../../libs/get-trace.js'; | ||
import { Queue } from '../core/queue.js'; | ||
@@ -76,4 +77,15 @@ let delegate; | ||
delegate.on('click', elementsToTrack, handleClickEvent(eventData), true); | ||
// Fire all click events that were stored in the old queue used by o-tracking v2 | ||
const clickQueue = new Queue('clicks'); | ||
sendAllEventsFromQueue(clickQueue); | ||
}; | ||
function sendAllEventsFromQueue(queue) { | ||
const nextLink = queue.shift(); | ||
if (nextLink) { | ||
core.track(nextLink, () => sendAllEventsFromQueue(queue)); | ||
} | ||
} | ||
const click = { | ||
@@ -80,0 +92,0 @@ init |
@@ -80,3 +80,3 @@ /* eslint-env mocha */ | ||
try { | ||
proclaim.equal(navigator.sendBeacon.args[0][0], 'https://spoor-api.ft.com/px.gif?type=video:seek'); | ||
proclaim.equal(navigator.sendBeacon.args[0][0], 'https://spoor-api.ft.com/ingest?type=video:seek'); | ||
proclaim.ok(navigator.sendBeacon.called); | ||
@@ -116,3 +116,3 @@ navigator.sendBeacon.restore(); | ||
proclaim.ok(dummyXHR.withCredentials, 'withCredentials'); | ||
proclaim.ok(dummyXHR.open.calledWith("POST", "https://spoor-api.ft.com/px.gif?type=video:seek", true), 'is POST'); | ||
proclaim.ok(dummyXHR.open.calledWith("POST", "https://spoor-api.ft.com/ingest?type=video:seek", true), 'is POST'); | ||
proclaim.ok(dummyXHR.setRequestHeader.calledWith('Content-type', 'application/json'), 'is application/json'); | ||
@@ -147,3 +147,4 @@ proclaim.ok(dummyXHR.send.calledOnce, 'calledOnce'); | ||
try { | ||
const payload = dummyImage.src.split('?')[1]; | ||
const [domain, payload] = dummyImage.src.split('?'); | ||
proclaim.equal(domain, "https://spoor-api.ft.com/px.gif"); | ||
proclaim.equal(decodeURIComponent(payload), 'type=video:seek&data={"system":{"transport":"image","is_live":true},"id":"1.199.83760034665465.1432907605043.-56cf00f","meta":{"page_id":"page_id","type":"event"},"user":{"spoor_session":"MS4zMTMuNTYxODY1NTk0MjM4MDQuMTQzMjkwNzYwNTAzNi4tNTZjZjAwZg==","spoor_id":"value3"},"device":{"user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34"},"category":"video","action":"seek","context":{"key":"pos","value":"10","parent_id":"1.990.74606760405.1432907605040.-56cf00f"}}'); | ||
@@ -150,0 +151,0 @@ proclaim.equal(dummyImage.addEventListener.args[0][0], 'error'); |
@@ -44,2 +44,41 @@ /* eslint-env mocha */ | ||
describe('when the old clicks queue exists', function() { | ||
const clickEventStoredInQueue = { | ||
"created_at": 1625589236422, | ||
"item": { | ||
"server": "https://spoor-api.ft.com/ingest", | ||
"context": { | ||
"product": "desktop", | ||
"url": "https://www.example.com/", | ||
"href": "https://www.example.com/", | ||
}, | ||
"action": "click", | ||
"category": "cta" | ||
} | ||
}; | ||
beforeEach(function() { | ||
// Add the click event to the old 'clicks' queue which o-tracking v2 uses | ||
new Queue('clicks').replace([clickEventStoredInQueue]); | ||
}); | ||
afterEach(function() { | ||
// Remove the events from the old 'clicks' queue | ||
new Queue('clicks').replace([]); | ||
}); | ||
it('should track an event for a click stored on the old clicks queue', function (done) { | ||
click.init("blah", '#anchorA'); | ||
setTimeout(() => { | ||
try { | ||
proclaim.equal(core.track.calledOnce, true, "click event tracked"); | ||
proclaim.deepStrictEqual(core.track.firstCall.firstArg, clickEventStoredInQueue); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}, 10); | ||
}); | ||
}); | ||
it('should track an event for a click', function (done) { | ||
@@ -46,0 +85,0 @@ |
338802
8379