Skip to content

Commit 4aacd19

Browse files
author
Yuraima Estevez
authored
Ye/add google params (#8615)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Follow up to #8602 to figure out which event is right <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 696473b commit 4aacd19

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

.changeset/mean-tables-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'polaris.shopify.com': minor
3+
---
4+
5+
Added search event that sets the default google parameters in addition to custom

polaris.shopify.com/src/components/GlobalSearch/GlobalSearch.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,26 @@ function captureSearchEvent(
4848
resultRank: number,
4949
selectedResult?: string,
5050
) {
51-
const eventParams = {
51+
// if nothings been searched we don't care about it
52+
if (!searchTerm) return;
53+
54+
const customParams = {
5255
searchTerm,
5356
resultRank,
5457
selectedResult,
5558
category: 'engagement',
5659
};
5760

58-
if (searchTerm) {
59-
window.gtag('event', 'customSearch', eventParams);
60-
}
61+
const googleParams = {
62+
event_category: resultRank > 0 ? 'engagement' : 'exit',
63+
event_label: selectedResult,
64+
value: resultRank,
65+
};
66+
67+
// i honestly have no idea which one of thes is the right set up for the google analytics version we have so let's try both
68+
// and keep the one that works
69+
window.gtag('event', 'customSearch', customParams);
70+
window.gtag('event', 'Global Search', googleParams);
6171
}
6272

6373
function scrollIntoView() {

0 commit comments

Comments
 (0)