Skip to content

Commit c6e12d0

Browse files
quantcast: cleanup
1 parent 3df479c commit c6e12d0

File tree

2 files changed

+75
-50
lines changed

2 files changed

+75
-50
lines changed

lib/providers/quantcast.js

+38-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1-
// https://www.quantcast.com/learning-center/guides/using-the-quantcast-asynchronous-tag/
21

3-
var Provider = require('../provider')
4-
, load = require('load-script');
2+
var integration = require('../integration')
3+
, load = require('load-script');
54

65

7-
module.exports = Provider.extend({
6+
/**
7+
* Expose `Quantcast` integration.
8+
*/
89

9-
name : 'Quantcast',
10+
var Quantcast = module.exports = integration('Quantcast');
1011

11-
key : 'pCode',
1212

13-
defaults : {
14-
pCode : null
15-
},
13+
/**
14+
* Required key.
15+
*/
1616

17-
initialize : function (options, ready) {
18-
window._qevents = window._qevents || [];
19-
window._qevents.push({ qacct: options.pCode });
20-
load({
21-
http : 'http://edge.quantserve.com/quant.js',
22-
https : 'https://secure.quantserve.com/quant.js'
23-
}, ready);
24-
}
17+
Quantcast.prototype.key = 'pCode';
2518

26-
});
19+
20+
/**
21+
* Default options.
22+
*/
23+
24+
Quantcast.prototype.defaults = {
25+
// your quantcast p code (required)
26+
pCode: null
27+
};
28+
29+
30+
/**
31+
* Initialize.
32+
*
33+
* https://www.quantcast.com/learning-center/guides/using-the-quantcast-asynchronous-tag/
34+
*
35+
* @param {Object} options
36+
* @param {Function} ready
37+
*/
38+
39+
Quantcast.prototype.initialize = function (options, ready) {
40+
window._qevents || (window._qevents = []);
41+
window._qevents.push({ qacct: options.pCode });
42+
load({
43+
http: 'http://edge.quantserve.com/quant.js',
44+
https: 'https://secure.quantserve.com/quant.js'
45+
}, ready);
46+
};

test/providers/quantcast.js

+37-32
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
describe('Quantcast', function () {
2-
3-
var analytics = require('analytics');
4-
5-
6-
describe('initialize', function () {
7-
8-
this.timeout(10000);
9-
10-
it('should call ready and load library', function (done) {
11-
var spy = sinon.spy()
12-
, push = Array.prototype.push;
131

14-
expect(window._qevents).to.be(undefined);
15-
16-
analytics.ready(spy);
17-
analytics.initialize({ 'Quantcast' : test['Quantcast'] });
2+
describe('Quantcast', function () {
183

19-
expect(window._qevents).not.to.be(undefined);
20-
expect(window._qevents.push).to.equal(push);
4+
var analytics = window.analytics || require('analytics')
5+
, assert = require('assert')
6+
, sinon = require('sinon')
7+
, when = require('when');
8+
9+
var settings = {
10+
pCode: 'x'
11+
};
12+
13+
before(function (done) {
14+
this.timeout(10000);
15+
this.spy = sinon.spy();
16+
analytics.ready(this.spy);
17+
analytics.initialize({ Quantcast: settings });
18+
this.integration = analytics._integrations.Quantcast;
19+
this.options = this.integration.options;
20+
when(function () { return window.__qc; }, done);
21+
});
22+
23+
describe('#key', function () {
24+
it('pCode', function () {
25+
assert(this.integration.key == 'pCode');
26+
});
27+
});
2128

22-
// When the library loads, it will overwrite the push method.
23-
var interval = setInterval(function () {
24-
if (window._qevents.push === push) return;
25-
expect(window._qevents.push).not.to.equal(push);
26-
expect(window.__qc).not.to.be(undefined);
27-
expect(spy.called).to.be(true);
28-
clearInterval(interval);
29-
done();
30-
}, 20);
31-
});
29+
describe('#defaults', function () {
30+
it('pCode', function () {
31+
assert(this.integration.defaults.pCode === null);
32+
});
33+
});
3234

33-
it('should store options', function () {
34-
analytics.initialize({ 'Quantcast' : test['Quantcast'] });
35-
expect(analytics._providers[0].options.pCode).to.equal(test['Quantcast']);
36-
});
35+
describe('#initialize', function () {
36+
it('should call ready', function () {
37+
assert(this.spy.called);
38+
});
3739

40+
it('should store options', function () {
41+
assert(this.options.pCode == settings.pCode);
3842
});
43+
});
3944

4045
});

0 commit comments

Comments
 (0)