Skip to content

Commit

Permalink
6.8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
piano-analytics committed Apr 3, 2023
1 parent 4aaadb0 commit 0e1d960
Show file tree
Hide file tree
Showing 14 changed files with 2,363 additions and 2,246 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.8.3
### New
- Updated the build with a new generated ES5-compatible file (`/dist/browser/piano-analytics.es5.js`)

## 6.8.2
### Fixes
- Fixed an issue preventing various cookies from being deposited when not using Consent
Expand All @@ -17,7 +21,6 @@
- Changed request's headers sent in hits for browserless
- Added a fallback to send hit requests (using fetch api) when sendBeacon is blocked due to its limitations


## 6.7.0
### Fixes
- Handle `queueVarName` conflict (no more crash, console log)
Expand Down
6 changes: 6 additions & 0 deletions babel.config-with-polyfills.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [["polyfill-corejs3", { "method": "usage-pure", "version": "3.20" }]]
}
18 changes: 10 additions & 8 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.8.2",
"version": "6.8.3",
"main": "dist/browserless/piano-analytics.cjs.js",
"module": "dist/browserless/piano-analytics.esm.js",
"browser": "dist/browser/piano-analytics.umd.js",
Expand All @@ -26,32 +26,34 @@
"prebuild:react-native": "grunt copy:http-react-native",
"clean": "grunt copy:http-clean",
"rollup:browser": "npm run prebuild:browser && rollup --config rollup.config-browser.js && npm run clean",
"rollup:browser-polyfills": "npm run prebuild:browser && rollup --config rollup.config-browser-polyfills.js && npm run clean",
"rollup:node": "npm run prebuild:node && rollup --config rollup.config-node.js && npm run clean",
"rollup:react-native": "npm run prebuild:react-native && rollup --config rollup.config-react-native.js && npm run clean",
"build": "npm run rollup:browser --omit=dev && npm run rollup:node --omit=dev && npm run rollup:react-native --omit=dev",
"build": "npm run rollup:browser --omit=dev && npm run rollup:browser-polyfills --omit=dev && npm run rollup:node --omit=dev && npm run rollup:react-native --omit=dev",
"test": "npm run test:browser && npm run test:node",
"test:browser": "npm run rollup:browser && karma start",
"test:node": "npm run rollup:node && node test/node.run.js"
},
"devDependencies": {
"@babel/core": "7.20.5",
"@babel/core": "7.20.12",
"@babel/preset-env": "7.20.2",
"@rollup/plugin-babel": "6.0.3",
"babel-plugin-polyfill-corejs3": "^0.7.1",
"chai": "4.3.7",
"eslint": "8.29.0",
"eslint": "8.33.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.1.1",
"grunt": "1.5.3",
"grunt": "1.6.0",
"grunt-contrib-copy": "^1.0.0",
"karma": "6.4.1",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "3.1.1",
"karma-mocha": "2.0.1",
"load-grunt-tasks": "5.1.0",
"mocha": "10.1.0",
"puppeteer": "19.3.0",
"mocha": "10.2.0",
"puppeteer": "19.6.2",
"rollup": "2.79.1",
"rollup-plugin-eslint": "7.0.0",
"rollup-plugin-replace": "2.2.0",
Expand Down
31 changes: 31 additions & 0 deletions rollup.config-browser-polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {babel} from '@rollup/plugin-babel';
import {eslint} from 'rollup-plugin-eslint';
import {uglify} from 'rollup-plugin-uglify';
import replace from 'rollup-plugin-replace';
import * as path from "path";

export default {
input: 'src/exports.js',
plugins: [
eslint({
configFile: './src/.eslintrc.json'
}),
replace({
BUILD_BROWSER: 'true'
}),
babel({configFile: path.resolve(__dirname, 'babel.config-with-polyfills.json'), babelHelpers: 'bundled'}),
process.env.NODE_ENV === 'production' && uglify()
],
output: [
{
file: 'dist/browser/piano-analytics.es5.js',
format: 'iife',
name: 'pianoAnalytics'
},
{
file: 'dist/browser/piano-analytics.es5.umd.js',
format: 'umd',
name: 'pianoAnalytics'
}
]
};
3 changes: 2 additions & 1 deletion rollup.config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {babel} from '@rollup/plugin-babel';
import {eslint} from 'rollup-plugin-eslint';
import {uglify} from 'rollup-plugin-uglify';
import replace from 'rollup-plugin-replace';
import * as path from "path";

export default {
input: 'src/exports.js',
Expand All @@ -12,7 +13,7 @@ export default {
replace({
BUILD_BROWSER: 'true'
}),
babel({babelHelpers: 'bundled'}),
babel({configFile: path.resolve(__dirname, 'babel.config.json'), babelHelpers: 'bundled'}),
process.env.NODE_ENV === 'production' && uglify()
],
output: [
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.8.2',
'version': '6.8.3',
'minHeartbeat': 5,
'minBufferingHeartbeat': 1,
'queueVarName': '_paq',
Expand Down
106 changes: 55 additions & 51 deletions src/core/steps/metadata.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ function metadataStep(pa, model, nextSteps) {
model.setProperty('browser_language', languageSplitted[0]);
model.setProperty('browser_language_local', languageSplitted[1]);
model.setProperty('previous_url', document.referrer || '');
if(document.title){
if (document.title) {
model.setProperty('page_title_html', document.title);
}
const eventUrlWithQueryString = model.getConfiguration('addEventURL').toString() === 'true';
if (eventUrlWithQueryString || (model.getConfiguration('addEventURL') === 'withoutQS')) {
model.setProperty('page_url', eventUrlWithQueryString ? window.location.href.split('#')[0] : `${window.location.protocol}//${window.location.host}${window.location.pathname}`);
}

try {
window.navigator.userAgentData.getHighEntropyValues([
'architecture',
Expand All @@ -79,56 +80,8 @@ function metadataStep(pa, model, nextSteps) {
'uaFullVersion',
'fullVersionList'
])
.then(function (ua) {
function _isDefined(variable) {
return typeof variable !== 'undefined';
}

const properties = [
{
metric: 'brands',
property: 'ch_ua'
},
{
metric: 'architecture',
property: 'ch_ua_arch'
},
{
metric: 'bitness',
property: 'ch_ua_bitness'
},
{
metric: 'fullVersionList',
property: 'ch_ua_full_version_list'
},
{
metric: 'mobile',
property: 'ch_ua_mobile'
},
{
metric: 'model',
property: 'ch_ua_model'
},
{
metric: 'platform',
property: 'ch_ua_platform'
},
{
metric: 'platformVersion',
property: 'ch_ua_platform_version'
},
{
metric: 'uaFullVersion',
property: 'ch_ua_full_version'
}
];
if (_isDefined(ua)) {
for (let i = 0; i < properties.length; i++) {
if (_isDefined(properties[i].metric)) {
model.setProperty(properties[i].property, ua[properties[i].metric]);
}
}
}
.then(function (userAgentData) {
_addUserAgentMetadata(model, userAgentData);
})
.finally(function () {
nextStep(pa, model, nextSteps);
Expand All @@ -140,5 +93,56 @@ function metadataStep(pa, model, nextSteps) {
nextStep(pa, model, nextSteps);
}
}
function _isDefined(variable) {
return typeof variable !== 'undefined';
}

function _addUserAgentMetadata(model, ua) {
const properties = [
{
metric: 'brands',
property: 'ch_ua'
},
{
metric: 'architecture',
property: 'ch_ua_arch'
},
{
metric: 'bitness',
property: 'ch_ua_bitness'
},
{
metric: 'fullVersionList',
property: 'ch_ua_full_version_list'
},
{
metric: 'mobile',
property: 'ch_ua_mobile'
},
{
metric: 'model',
property: 'ch_ua_model'
},
{
metric: 'platform',
property: 'ch_ua_platform'
},
{
metric: 'platformVersion',
property: 'ch_ua_platform_version'
},
{
metric: 'uaFullVersion',
property: 'ch_ua_full_version'
}
];
if (_isDefined(ua)) {
for (let i = 0; i < properties.length; i++) {
if (_isDefined(properties[i].metric)) {
model.setProperty(properties[i].property, ua[properties[i].metric]);
}
}
}
}

export {metadataStep};
82 changes: 45 additions & 37 deletions test/browser/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@ describe('Asynchronous tagging :', function () {
'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._paq = window._paq || [];
_paq.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);
Utility.promiseThrowCatcher(done, function () {
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._paq = window._paq || [];
_paq.push(['sendEvent', 'tata', {
'myOnlyProp': 'one'
}, {
onBeforeSend: function (pianoAnalytics2, model2) {
Utility.promiseThrowCatcher(done, function () {
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);
});
it('Should work properly after pianoAnalytics is instancied and variable name has been overrided', function (done) {
it('Should work properly after pianoAnalytics is instanced and variable name has been override', function (done) {
// _paq should be ignored
var _paq = window._paq = window._paq || [];
_paq.push(['sendEvent', 'tata', {}, {
Expand All @@ -70,24 +74,28 @@ describe('Asynchronous tagging :', function () {
'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);
Utility.promiseThrowCatcher(done, function () {
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) {
Utility.promiseThrowCatcher(done, function () {
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);
Expand Down
Loading

0 comments on commit 0e1d960

Please sign in to comment.