@prestashopcorp/segment-vue
Advanced tools
Comparing version 2.1.7 to 2.2.0
/*! | ||
* @prestashopcorp/segment-vue v2.1.7 | ||
* (c) 2021 undefined | ||
* @prestashopcorp/segment-vue v2.2.0 | ||
* (c) 2022 undefined | ||
* Released under the MIT License. | ||
@@ -41,2 +41,26 @@ */ | ||
analytics.load = function (key, options) { | ||
var source = "https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js"; | ||
loadScript(source, function (error, script) { | ||
if (error) { | ||
console.warn("Ops! Is not possible to load Segment Analytics script"); | ||
return; | ||
} | ||
var poll = setInterval(function () { | ||
if (!window.analytics) { | ||
return; | ||
} | ||
clearInterval(poll); | ||
// the callback is fired when window.analytics is available and before any other hit is sent | ||
if (callback && typeof callback === "function") { | ||
callback(); | ||
} | ||
}, 10); | ||
}); | ||
analytics._loadOptions = options; | ||
}; | ||
// Define a factory to create stubs. These are placeholders | ||
@@ -49,3 +73,3 @@ // for methods in Analytics.js so that you never have to wait | ||
var args = Array.prototype.slice.call(arguments); | ||
if (config.debug === true) { | ||
if (config.debug) { | ||
if (window.console && console.log) { | ||
@@ -91,23 +115,4 @@ console.log("[Segment Analytics Debug]: " + method + " method called with " + args.length + " args"); | ||
if (config.debug === false) { | ||
var source = "https://cdn.segment.com/analytics.js/v1/" + config.id + "/analytics.min.js"; | ||
loadScript(source, function (error, script) { | ||
if (error) { | ||
console.warn("Ops! Is not possible to load Segment Analytics script"); | ||
return; | ||
} | ||
var poll = setInterval(function () { | ||
if (!window.analytics) { | ||
return; | ||
} | ||
clearInterval(poll); | ||
// the callback is fired when window.analytics is available and before any other hit is sent | ||
if (callback && typeof callback === "function") { | ||
callback(); | ||
} | ||
}, 10); | ||
}); | ||
if (!config.debug) { | ||
analytics.load(config.id, config.settings); | ||
} else { | ||
@@ -143,3 +148,4 @@ // Still run the callback in debug mode. | ||
debug: false, | ||
pageCategory: "" | ||
pageCategory: "", | ||
settings: {} | ||
}, options); | ||
@@ -181,15 +187,2 @@ | ||
} | ||
// Setup instance access | ||
// if (window.analytics && !Vue.hasOwnProperty("$segment") && !Vue.prototype.hasOwnProperty("$segment")) { | ||
// Object.defineProperty(Vue, "$segment", { | ||
// get() { | ||
// return window.analytics; | ||
// }, | ||
// }); | ||
// Object.defineProperty(Vue.prototype, "$segment", { | ||
// get() { | ||
// return window.analytics; | ||
// }, | ||
// }); | ||
// } | ||
}; | ||
@@ -196,0 +189,0 @@ |
{ | ||
"name": "@prestashopcorp/segment-vue", | ||
"version": "2.1.7", | ||
"version": "2.2.0", | ||
"description": "plugin vue for segment", | ||
@@ -5,0 +5,0 @@ "main": "dist/@prestashopcorp/segment-vue.js", |
104
README.md
@@ -16,5 +16,6 @@ # vue-segment | ||
``` | ||
### Vue 2 | ||
```js | ||
import Vue from 'vue' | ||
@@ -25,3 +26,3 @@ import SegmentVue from '@prestashopcorp/segment-vue' | ||
id: 'XXXXX', | ||
}); | ||
}) | ||
``` | ||
@@ -32,4 +33,3 @@ | ||
```js | ||
import { createApp } from "vue"; | ||
import { createApp } from 'vue' | ||
import SegmentVue from '@prestashopcorp/segment-vue' | ||
@@ -41,8 +41,47 @@ | ||
id: 'XXXXX', | ||
}); | ||
}) | ||
``` | ||
## LoadOptions | ||
For GDPR it's necessary to desactivate all integrations | ||
An Example below : | ||
```js | ||
import Vue from 'vue' | ||
import SegmentVue from '@prestashopcorp/segment-vue' | ||
Vue.use(SegmentVue, { | ||
id: 'XXXXX', | ||
settings: { | ||
integrations: { | ||
All: false, | ||
'Segment.io': true, | ||
}, | ||
}, | ||
}) | ||
``` | ||
### For example with axeptio | ||
```js | ||
axeptio.on('cookies:complete', function (choices) { | ||
if (choices.google_analytics && choices.hotjar) { | ||
window.analytics.load(SEGMENT_KEY, { | ||
integrations: { | ||
All: false, | ||
'Segment.io': true, | ||
'Google Analytics': true, | ||
Hotjar: true, | ||
}, | ||
}) | ||
window.location.reload() | ||
} | ||
}) | ||
``` | ||
## Identify | ||
add this on your layout file | ||
```js | ||
@@ -58,11 +97,11 @@ created(){ | ||
## Track | ||
add this on each method click | ||
```js | ||
handleClick(){ | ||
this.$segment.track(NAME_YOUR_TRACK, | ||
this.$segment.track(NAME_YOUR_TRACK, | ||
//optional properties | ||
{ | ||
{ | ||
name: "it's your track name", | ||
@@ -74,4 +113,4 @@ category: "ps_metrics", | ||
## Options | ||
## Options | ||
### route track option | ||
@@ -82,27 +121,29 @@ | ||
### Vue 2 | ||
```js | ||
export default { | ||
path: "dashboard", | ||
name: "dashboard", //Set name on each route | ||
path: 'dashboard', | ||
name: 'dashboard', //Set name on each route | ||
component: DashboardApp, | ||
}; | ||
} | ||
Vue.use(SegmentVue, { | ||
id: 'XXXXX', | ||
router | ||
}); | ||
router, | ||
}) | ||
``` | ||
### Vue 3 | ||
```js | ||
export default { | ||
path: "dashboard", | ||
name: "dashboard", //Set name on each route | ||
path: 'dashboard', | ||
name: 'dashboard', //Set name on each route | ||
component: DashboardApp, | ||
}; | ||
} | ||
app.use(SegmentVue, { | ||
id: 'XXXXX', | ||
router | ||
}); | ||
router, | ||
}) | ||
``` | ||
@@ -114,12 +155,12 @@ | ||
export default { | ||
name: "activity", | ||
path: "activity", | ||
meta: {exclude: true}, // <= add this key in your route object, true to exclude, false to track | ||
name: 'activity', | ||
path: 'activity', | ||
meta: { exclude: true }, // <= add this key in your route object, true to exclude, false to track | ||
component: () => | ||
import( | ||
/* webpackChunkName: "dashboardActivity" */ "@/core/dashboard/pages/ActivityApp" | ||
/* webpackChunkName: "dashboardActivity" */ '@/core/dashboard/pages/ActivityApp' | ||
), | ||
redirect: "activity/revenue", | ||
redirect: 'activity/revenue', | ||
children: [RevenueRouter, OrderRouter, ConversionRouter, VisitRouter], | ||
}; | ||
} | ||
``` | ||
@@ -132,2 +173,3 @@ | ||
### Vue 2 | ||
```js | ||
@@ -137,7 +179,8 @@ Vue.use(SegmentVue, { | ||
router, | ||
pageCategory: "ps_metrics_" | ||
}); | ||
pageCategory: 'ps_metrics_', | ||
}) | ||
``` | ||
### Vue 3 | ||
```js | ||
@@ -147,5 +190,4 @@ app.use(SegmentVue, { | ||
router, | ||
pageCategory: "ps_metrics_" | ||
}); | ||
pageCategory: 'ps_metrics_', | ||
}) | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
108517
5
2757
183
1