Skip to content

Commit 4176a8c

Browse files
committed
SPA cleanup
1 parent 7eaea94 commit 4176a8c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/connections/sources/catalog/libraries/website/javascript/single-page-apps.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ title: Single Page Applications
33
strat: ajs
44
---
55

6-
While Single Page Apps (SPAs) are great for many reasons, they do require some extra consideration in order to set up client-side tracking than with a traditional webpage.
6+
While Single Page Apps (SPAs) offer many benefits, setting up client-side tracking requires extra consideration compared to traditional web pages.
77

8-
By default, the Segment analytics.js library doesn’t generate or store the referrer value. Instead, the referrer value you see in the payload is the value returned by `document.referrer` directly from the browser, and the URL value is the canonical URL on the page.
8+
By default, the Segment Analytics.js library doesn’t generate or store the referrer value. Instead, the `referrer` value you see in the payload is the value returned by `document.referrer` directly from the browser, and the `url` value is the canonical URL on the page.
99

10-
When a user navigates between pages on an SPA website, there won’t be a referrer because there is no concept of a new page since it’s all a single page load. This means that the referrer will always be the same as it was on the first page call where someone was first directed to your site. However, in order to circumvent this, you can manually set the referrer and URL in your Segment calls by updating the context object.
10+
When a user navigates between pages on an SPA website, there won’t be a referrer because there is no concept of a new page since it’s all a single page load. This means that the referrer will always be the same as it was on the first page call where someone was first directed to your site. However, in order to circumvent this, you can manually set the `referrer` and `url` values in your Segment calls by updating the context object.
1111

12-
For example, a Page call with the referrer and URL manually set looks like this:
12+
For example, a Page call with the `referrer` and `url` manually set looks like this:
1313

1414
```js
1515
analytics.page({
@@ -29,20 +29,20 @@ analytics.track('Example Event', {}, {page: {
2929

3030
## Tracking emulated page views
3131

32-
Your application should update the URL in the address bar to emulate traditional webpage navigation. Full page requests aren't made in most of these instances since the resources are loaded on initial page load. This means that the Page call in the traditional analytics.js snippet won't fire again as a user navigates around your site.
32+
Your application should update the URL in the address bar to emulate traditional webpage navigation. Full page requests aren't made in most of these instances since the resources are loaded on initial page load. This means that the Page call in the traditional Analytics.js snippet won't fire again as a user navigates around your site.
3333

34-
You should still place the snippet in the head of your site, but you should remove the Page call and fire it whenever you're emulating a page load. Segment recommends that you call [Page](/docs/connections/sources/catalog/libraries/website/javascript/#page) from the same block of logic that updates the view and URL path like below:
34+
You should still place the snippet in the `<head>` of your site, but you should remove the Page call and fire it whenever you're emulating a page load. Segment recommends that you call [Page](/docs/connections/sources/catalog/libraries/website/javascript/#page) from the same block of logic that updates the view and URL path, as shown below:
3535

3636
```js
3737
// The new view has been called to render
3838
analytics.page("Home")
3939
```
4040

41-
To track more than the page field, pass those fields in as additional properties. Segment recommends that you use variables to set information about page properties, rather than hard-coding. In most SPA frameworks, you can automate this by attaching the Page call to the routing service.
41+
To track more than the page field, pass those fields in as additional properties. Segment recommends that you use variables to set information about page properties, rather than hardcoding them. In most SPA frameworks, you can automate this by attaching the Page call to the routing service.
4242

4343
## What to do with code that lives in the analytics.ready() function?
4444

45-
Analytics.js ships with a function called analytics.ready() which lets you make calls to the native integrations that Segment loads for you before they actually initialize. For instance, this is where you could choose to load a live chat widget only for users that you haven't yet identified with a userId.
45+
Analytics.js ships with a function called `analytics.ready()` which lets you make calls to the native integrations that Segment loads for you before they actually initialize. For instance, this is where you could choose to load a live chat widget only for users that you haven't yet identified with a `userId`.
4646

4747
Since the code in the head of your website is executed only on initial page load or a refresh, you can still make calls to those native tools, but they won't run on each emulated page view.
4848

0 commit comments

Comments
 (0)