Skip to content

Commit

Permalink
6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
piano-analytics committed Aug 25, 2022
1 parent cddde14 commit f596636
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.4.0

### Added or Changed
- New configuration key `queueVarName` to set the global variable name used in asynchronous tagging

## 6.3.0

### Added or Changed
Expand Down
12 changes: 6 additions & 6 deletions 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.3.0",
"version": "6.4.0",
"main": "dist/browserless/piano-analytics.cjs.js",
"module": "dist/browserless/piano-analytics.esm.js",
"browser": "dist/browser/piano-analytics.umd.js",
Expand Down Expand Up @@ -31,11 +31,11 @@
"test:browserless": "npm run rollup:browserless && node test/browserless.run.js"
},
"devDependencies": {
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/core": "7.18.10",
"@babel/preset-env": "7.18.10",
"@rollup/plugin-babel": "5.3.1",
"chai": "4.3.6",
"eslint": "8.19.0",
"eslint": "8.21.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-node": "11.1.0",
Expand All @@ -48,8 +48,8 @@
"karma-mocha": "2.0.1",
"load-grunt-tasks": "5.1.0",
"mocha": "10.0.0",
"puppeteer": "15.3.0",
"rollup": "2.75.7",
"puppeteer": "16.1.0",
"rollup": "2.77.3",
"rollup-plugin-eslint": "7.0.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-uglify": "6.0.4"
Expand Down
4 changes: 2 additions & 2 deletions src/business/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function _functionCallFromString(root, target, params, context) {
}
}

function preloadTagging(root, srcArray, isAsync) {
function preloadTagging(root, srcArray, isAsync, asyncArrayName) {
const context = isAsync ? null : root;
const configOverrideArray = srcArray || [];
if (configOverrideArray.length > 0) {
Expand All @@ -17,7 +17,7 @@ function preloadTagging(root, srcArray, isAsync) {
}
}
if (isAsync) {
window._paq = {
window[asyncArrayName] = {
push: function (paramsArray) {
_functionCallFromString(root, paramsArray[0].split('.'), paramsArray.slice(1));
}
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default {
],
'storageVisitor': 'pa_vid',
'storageUser': 'pa_user',
'version': '6.3.0',
'version': '6.4.0',
'minHeartbeat': 5,
'minBufferingHeartbeat': 1,
'queueVarName': '_paq',
'privacy': {
'storageKey': 'pa_privacy',
'storageKeys': {
Expand Down
5 changes: 3 additions & 2 deletions src/core/PianoAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ function PianoAnalytics(configuration) {
AVInsights(this);

if (BUILD_BROWSER) {
window._paq = window._paq || [];
preloadTagging(this, window._paq, true);
const asyncName = this.getConfiguration('queueVarName');
window[asyncName] = window[asyncName] || [];
preloadTagging(this, window[asyncName], true, asyncName);
}
}

Expand Down
46 changes: 46 additions & 0 deletions test/browser/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Asynchronous tagging :', function () {
Utility.clearStorage(pa);
window._pac = undefined;
window._paq = undefined;
window._pasync = undefined;
});
it('Should work properly after pianoAnalytics is instancied', function (done) {
window._paq = window._paq || [];
Expand Down Expand Up @@ -45,4 +46,49 @@ describe('Asynchronous tagging :', function () {
}]);
globalPA = new pa.PA(config);
});
it('Should work properly after pianoAnalytics is instancied and variable name has been overrided', function (done) {
// _paq should be ignored
var _paq = window._paq = window._paq || [];
_paq.push(['sendEvent', 'tata', {}, {
onBeforeSend: function () {
throw new Error('Should not execute this code');
}
}]);
// here we change the async variable we want to use in our tagging
window._pac = window._pac || {privacy: []};
_pac.queueVarName = '_pasync';

// new custom async tagging variable, _paq is now untouched
window._pasync = window._pasync || [];
_pasync.push(['setConfiguration', 'collectDomain', 'collectDomainTestValue']);
_pasync.push(['setProperties', {
'myProperty': 1,
'myOtherProperty': 'two',
}]);
_pasync.push(['sendEvent', 'toto', {
'myThirdProp': 'three'
}, {
onBeforeSend: function (pianoAnalytics, model, next) {
expect(model.build.data.events[0].data['myProperty']).to.equal(1);
expect(model.build.data.events[0].data['myOtherProperty']).to.equal('two');
expect(model.build.data.events[0].data['myThirdProp']).to.equal('three');
expect(model.getConfiguration('collectDomain')).to.equal('collectDomainTestValue');
window._pasync = window._pasync || [];
_pasync.push(['sendEvent', 'tata', {
'myOnlyProp': 'one'
}, {
onBeforeSend: function (pianoAnalytics2, model2) {
expect(model2.build.data.events[0].data['myProperty']).to.equal(undefined);
expect(model2.build.data.events[0].data['myOtherProperty']).to.equal(undefined);
expect(model2.build.data.events[0].data['myThirdProp']).to.equal(undefined);
expect(model2.build.data.events[0].data['myOnlyProp']).to.equal('one');
expect(model2.getConfiguration('collectDomain')).to.equal('collectDomainTestValue');
done();
}
}]);
next(false);
}
}]);
globalPA = new pa.PA(config);
});
});

0 comments on commit f596636

Please sign in to comment.