Skip to content

Commit d777997

Browse files
Jan Petrvvo
authored andcommitted
feat(analytics-widget): add a new parameter pushInitialSearch (#1963)
1 parent cce4f2e commit d777997

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

dev/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ search.addWidget(
5454
// }]);
5555
},
5656
triggerOnUIInteraction: true,
57+
pushInitialSearch: false,
5758
})
5859
);
5960

docs/_includes/widget-jsdoc/analytics.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
<span class="attr-infos">Default:<code class="attr-default">false</code>(<code>boolean</code>)</span>
1515
</p>
1616
<p class="attr-description">Trigger pushFunction after click on page or redirecting the page</p>
17+
<p class="attr-name">
18+
<span class='attr-optional'>`options.pushInitialSearch`<span class="show-description">…</span></span>
19+
<span class="attr-infos">Default:<code class="attr-default">true</code>(<code>boolean</code>)</span>
20+
</p>
21+
<p class="attr-description">Trigger pushFunction after the initial search</p>
1722

1823
<p class="attr-legend">* <span>Required</span></p>

src/widgets/analytics/analytics.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
* @param {Function} [options.pushFunction] Push function called when data are supposed to be pushed to analytic service
55
* @param {int} [options.delay=3000] Number of milliseconds between last search key stroke and calling pushFunction
66
* @param {boolean} [options.triggerOnUIInteraction=false] Trigger pushFunction after click on page or redirecting the page
7+
* @param {boolean} [options.pushInitialSearch=true] Trigger pushFunction after the initial search
78
* @return {Object}
89
*/
910
const usage = `Usage:
1011
analytics({
1112
pushFunction,
1213
[ delay=3000 ],
13-
[ triggerOnUIInteraction=false ]
14+
[ triggerOnUIInteraction=false ],
15+
[ pushInitialSearch=true ]
1416
})`;
1517
function analytics({
1618
pushFunction,
1719
delay = 3000,
1820
triggerOnUIInteraction = false,
21+
pushInitialSearch = true,
1922
} = {}) {
2023
if (!pushFunction) {
2124
throw new Error(usage);
@@ -106,6 +109,11 @@ function analytics({
106109

107110
let pushTimeout;
108111

112+
let isInitialSearch = true;
113+
if (pushInitialSearch === true) {
114+
isInitialSearch = false;
115+
}
116+
109117
return {
110118
init() {
111119
if (triggerOnUIInteraction === true) {
@@ -119,6 +127,12 @@ function analytics({
119127
}
120128
},
121129
render({results, state}) {
130+
if (isInitialSearch === true) {
131+
isInitialSearch = false;
132+
133+
return;
134+
}
135+
122136
cachedState = {results, state};
123137

124138
if (pushTimeout) {

0 commit comments

Comments
 (0)