Skip to content

Commit 6887896

Browse files
Change query parameter to search (#4897)
1 parent eba9e1f commit 6887896

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/guides/how-to-guides/collect-pageviews-serverside.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ With this approach, you might use a request "middleware" to log a `pageview` w
1010

1111
There are a few things to be mindful of if you want to make sure you can attribute these (anonymous) page views to the appropriate user in your client-side source (eg, for effectively joining these tables together to do down-funnel behavioral attribution). You'll want to ensure they share an `anonymousId` by respecting one if it's already there, and setting it yourself if not. To do that, you can read and modify the `ajs_anonymous_id` cookie value in the request.
1212

13-
Be sure to pass through as many fields as you can in our [page](https://segment.com/docs/connections/spec/page/) and [context](https://segment.com/docs/connections/spec/common/) spec, so that you get full functionality in any downstream tools you choose to enable. We recommend specifically ensuring you pass the **url, path, host, title, query, and referrer** in the message `properties` and **ip and user-agent** in the message `context` .
13+
Be sure to pass through as many fields as you can in our [page](https://segment.com/docs/connections/spec/page/) and [context](https://segment.com/docs/connections/spec/common/) spec, so that you get full functionality in any downstream tools you choose to enable. We recommend specifically ensuring you pass the **url, path, host, title, search, and referrer** in the message `properties` and **ip and user-agent** in the message `context` .
1414

1515
Here's an example of an express middleware function that covers all those edge cases!
1616

@@ -25,15 +25,15 @@ const app = express()
2525
const analytics = new Analytics('write-key')
2626

2727
app.use((req, res, next) => {
28-
const { query, cookies, url, path, ip, host } = req
28+
const { search, cookies, url, path, ip, host } = req
2929

3030
// populate campaign object with any utm params
3131
const campaign = {}
32-
if (query.utm_content) campaign.content = query.utm_content
33-
if (query.utm_campaign) campaign.name = query.utm_campaign
34-
if (query.utm_medium) campaign.medium = query.utm_medium
35-
if (query.utm_source) campaign.source = query.utm_source
36-
if (query.utm_term) campaign.keyword = query.utm_term
32+
if (search.utm_content) campaign.content = search.utm_content
33+
if (search.utm_campaign) campaign.name = search.utm_campaign
34+
if (search.utm_medium) campaign.medium = search.utm_medium
35+
if (search.utm_source) campaign.source = search.utm_source
36+
if (search.utm_term) campaign.keyword = search.utm_term
3737

3838
// grab userId if present
3939
let userId = null
@@ -53,7 +53,7 @@ app.use((req, res, next) => {
5353
const userAgent = req.get('User-Agent')
5454

5555
const properties = {
56-
query: stringify(query)
56+
search: stringify(query)
5757
referrer,
5858
path,
5959
host,

0 commit comments

Comments
 (0)