Skip to content

Commit

Permalink
6.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
piano-analytics committed Mar 6, 2024
1 parent bdd24e4 commit 098d4ed
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 6.14.1
### Fixes
- [browser] Fixed a bug when several `setProperty(ies)` and `sendEvent(s)` methods were chained without delays

## 6.14.0
### New
- [browser] New consent methods using `purposes`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "piano-analytics-js",
"description": "JavaScript library for Piano Analytics",
"version": "6.14.0",
"version": "6.14.1",
"main": "dist/browserless/piano-analytics.cjs.js",
"module": "dist/browserless/piano-analytics.esm.js",
"browser": "dist/browser/piano-analytics.umd.js",
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
],
'storageVisitor': 'pa_vid',
'storageUser': 'pa_user',
'version': '6.14.0',
'version': '6.14.1',
'minHeartbeat': 5,
'minBufferingHeartbeat': 1,
'queueVarName': '_paq',
Expand Down
26 changes: 19 additions & 7 deletions src/core/PianoAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function PianoAnalytics(configuration) {
this._queue = new PianoAnalyticsQueue(this);
this._properties = {};
this._sendEvent = _sendEvent;
this._setProperty = _setProperty;
this._deleteProperty = _deleteProperty;
_initPrivacy(this);
this.user = new User(this);
AVInsights(this);
Expand Down Expand Up @@ -131,6 +133,21 @@ function _sendEvent(events, options) {
}
}

function _setProperty(pa, property, value, options) {
if (pa._privacy.call('isPropAllowed', property)) {
pa._properties[property] = {
value: value,
options: options || {}
};
}
pa._queue.next();
}

function _deleteProperty(pa, property) {
delete pa._properties[property];
pa._queue.next();
}

function _processCallbackIfPresent(value, cb) {
if (cb) {
cb(value);
Expand All @@ -139,12 +156,7 @@ function _processCallbackIfPresent(value, cb) {
}

PianoAnalytics.prototype.setProperty = function (property, value, options) {
if (this._privacy.call('isPropAllowed', property)) {
this._properties[property] = {
value: value,
options: options || {}
};
}
this._queue.push(['_setProperty', this, property, value, options]);
};
PianoAnalytics.prototype.setProperties = function (properties, options) {
for (const prop in properties) {
Expand All @@ -154,7 +166,7 @@ PianoAnalytics.prototype.setProperties = function (properties, options) {
}
};
PianoAnalytics.prototype.deleteProperty = function (propertyName) {
delete this._properties[propertyName];
this._queue.push(['_deleteProperty', this, propertyName]);
};
PianoAnalytics.prototype.sendEvent = function (eventName, eventData, options) {
this._queue.push(['_sendEvent', [{name: eventName, data: eventData}], options]);
Expand Down
3 changes: 2 additions & 1 deletion test/node/visitorid.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ describe('Visitor id :', function () {
expect(visitorIdStored).to.equal(model.visitorId);
setTimeout(function () {
globalPA.sendEvent('tata', {test: 'visitor'}, {
onBeforeSend: function (pa2, model2) {
onBeforeSend: function (pa2, model2, next2) {
expect(model2.visitorId).to.equal(visitorIdStored);
next2(false);
}
});
}, 2000);
Expand Down
56 changes: 48 additions & 8 deletions test/shared/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('Properties :', function () {
}
});
});
it('Should not override values of privacy specific properties', function (done) {
it('Should be able to override values of privacy specific properties', function (done) {
globalPA.setProperty('visitor_privacy_consent', 'myconsent');
globalPA.setProperty('visitor_privacy_mode', 'test');
globalPA.sendEvent('toto', {'visitor_privacy_mode': 'mymode'}, {
Expand All @@ -200,7 +200,7 @@ describe('Properties :', function () {
}
});
});
it('Should not override values of metadata specific properties', function (done) {
it('Should be able to override values of metadata specific properties', function (done) {
globalPA.setProperty('event_collection_platform', '1');
globalPA.setProperty('event_collection_version', '22');
globalPA.sendEvent('toto', {
Expand Down Expand Up @@ -439,22 +439,22 @@ describe('Properties :', function () {
}
});
});
it('Should not override values of privacy specific properties', function (done) {
it('Should be able to override values of privacy specific properties', function (done) {
globalPA.setProperties({
'visitor_privacy_consent': 'myconsent',
'visitor_privacy_mode': 'test'
});
globalPA.sendEvent('toto', {'visitor_privacy_mode': 'mymode'}, {
globalPA.sendEvent('toto', {}, {
onBeforeSend: function (pianoanalytics, model) {
Utility.promiseThrowCatcher(done, function () {
expect(model.build.data.events[0].data['visitor_privacy_consent']).to.equal('myconsent');
expect(model.build.data.events[0].data['visitor_privacy_mode']).to.equal('mymode');
expect(model.build.data.events[0].data['visitor_privacy_mode']).to.equal('test');
done();
});
}
});
});
it('Should not override values of metadata specific properties', function (done) {
it('Should be able to override values of metadata specific properties', function (done) {
globalPA.setProperties({
'event_collection_platform': '1',
}, {events: ['tata']});
Expand All @@ -465,19 +465,59 @@ describe('Properties :', function () {
globalPA.setProperties({
'device_local_hour': '4'
}, {events: ['to*']});
globalPA.sendEvent('toto', {'device_timestamp_utc': '3'}, {
globalPA.sendEvent('toto', {}, {
onBeforeSend: function (pianoanalytics, model) {
Utility.promiseThrowCatcher(done, function () {
expect(model.build.data.events[0].data['event_collection_platform']).to.not.equal('1');
expect(model.build.data.events[0].data['event_collection_platform']).to.not.equal(undefined);
expect(model.build.data.events[0].data['event_collection_version']).to.equal('2');
expect(model.build.data.events[0].data['device_timestamp_utc']).to.equal('3');
expect(model.build.data.events[0].data['device_timestamp_utc']).to.equal('test');
expect(model.build.data.events[0].data['device_local_hour']).to.equal('4');
done();
});
}
});
});
it('Should be synchronized with sendEvent(s) method (using the same queue)', function (done) {
let call1 = false;
let call2 = false;
globalPA.setProperties({
'event_collection_version': '1',
'device_timestamp_utc': '2'
});
globalPA.sendEvent('toto', {}, {
onBeforeSend: function (pianoanalytics, model, next) {
Utility.promiseThrowCatcher(done, function () {
expect(model.build.data.events[0].data['event_collection_version']).to.equal('1');
expect(model.build.data.events[0].data['device_timestamp_utc']).to.equal('2');
call1 = true;
if (call2) {
done();
} else {
next(false);
}
});
}
});
globalPA.setProperties({
'event_collection_version': '3',
'device_timestamp_utc': '4'
});
globalPA.sendEvent('toto', {}, {
onBeforeSend: function (pianoanalytics, model) {
Utility.promiseThrowCatcher(done, function () {
expect(model.build.data.events[0].data['event_collection_version']).to.equal('3');
expect(model.build.data.events[0].data['device_timestamp_utc']).to.equal('4');
call2 = true;
if (call1) {
done();
} else {
next(false);
}
});
}
});
});
});
it('Should delete a property', function () {
globalPA.setProperty('custom', true);
Expand Down

0 comments on commit 098d4ed

Please sign in to comment.