-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(store_pagespixel): add legacy analytics support #28
Changes from 12 commits
3720e93
720ffd5
ef25a23
5152ee8
e462922
52da3a9
131c0b4
cd0de3d
0e9db59
00ddf38
231f6b3
d1d1f15
4cff913
fcbe05c
8281ae5
6c0f271
f5a355c
3ca3bb2
4c433ca
fe36c0d
b04b0e7
b160906
8dd1ecf
5c4d583
03a6734
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,29 +28,72 @@ First, install the library via [npm](https://www.npmjs.com/get-npm): | |
npm install @yext/analytics | ||
``` | ||
|
||
Next, import and initialize the library in your application. | ||
Next, import and initialize the library in your application. Yext currently has different analytics reporting features | ||
between Search and Pages and so they have slightly different interfaces for working with them. There is also a combined | ||
interface that you can use when you are building a Search experience entirely on Pages (e.g. a Locator or a Help Site). | ||
|
||
The experienceKey will come from your Answers experience on yext.com. You can signup for a free trial at [https://www.yext.com/free-trial/](https://www.yext.com/free-trial/). | ||
### Combined Analytics | ||
For a typical locator you will be using both Search and Pages analytics. | ||
|
||
The experienceKey will come from your Answers experience on yext.com. You can signup for a free trial at | ||
[https://www.yext.com/free-trial/](https://www.yext.com/free-trial/). | ||
|
||
The businessId and siteId can both be found in your account. | ||
|
||
```ts | ||
import { provideAnalytics } from '@yext/analytics'; | ||
|
||
const analytics = provideAnalytics({ | ||
experienceKey: '<your experience key>', | ||
experienceVersion: 'PRODUCTION', | ||
businessId: 123456, | ||
businessId: 123456, // this comes from the url of your Yext account | ||
featureId: 'My Locator', // the name of the feature in your features.json | ||
pageType: 'locator', // the type of page, can be 'entity', 'directory', 'locator', or 'static' | ||
product: 'storepages', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should product be? If it's always |
||
production: false, // set to true if you are in the production environment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Production is a pretty overloaded term for us. Is this production as in the production vs staging deploy? Or production vs. sandbox? Could also see someone confusing this with the Production answers experience tag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair point... it's just that staging doesn't exist anymore so I figured it made sense to flip the bit |
||
siteId: 654321, // the id of your site, you can find this in the url of your deploy page | ||
}); | ||
``` | ||
|
||
Now that we are initialized, we can add a page view. | ||
|
||
```ts | ||
analytics.pageView(); | ||
``` | ||
|
||
and if a user clicks on a search result, we can fire an appropriate event. | ||
|
||
```ts | ||
analytics.report({ | ||
type: 'CTA_CLICK', | ||
entityId: '1', | ||
verticalKey: 'people', | ||
searcher: 'VERTICAL', | ||
queryId: '12345678-1234-1234-1234-123456789012' | ||
}); | ||
``` | ||
|
||
### Search Analytics | ||
|
||
```ts | ||
import { provideSearchAnalytics } from '@yext/analytics'; | ||
|
||
const searchAnalytics = provideSearchAnalytics({ | ||
experienceKey: '<your experience key>', | ||
experienceVersion: 'PRODUCTION', | ||
businessId: 123456, // this comes from the url of your Yext account | ||
}); | ||
``` | ||
|
||
To use the library with Node, use the following import instead: | ||
```ts | ||
const { provideAnalytics } = require('@yext/analytics'); | ||
const { provideSearchAnalytics } = require('@yext/analytics'); | ||
``` | ||
|
||
Now that the analytics reporter is initialized, let's fire off an event: | ||
Now that the search analytics reporter is initialized, let's fire off an event: | ||
|
||
```ts | ||
analytics.report({ | ||
searchAnalytics.report({ | ||
type: 'CTA_CLICK', | ||
entityId: '1', | ||
verticalKey: 'people', | ||
|
@@ -59,15 +102,41 @@ analytics.report({ | |
}); | ||
``` | ||
|
||
### Analytics Event Types | ||
### Pages Analytics | ||
|
||
```ts | ||
import {providePagesAnalytics} from '@yext/analytics'; | ||
|
||
const pagesAnalytics = providePagesAnalytics({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to include the |
||
businessId: 123456, // this comes from the url of your Yext account | ||
featureId: 'My Page Set', // the name of the feature in your features.json | ||
pageType: 'entity', // the type of page, can be 'entity', 'directory', 'locator', or 'static' | ||
product: 'storepages', | ||
production: false, // set to true if you are in the production environment | ||
siteId: 654321, // the id of your site, you can find this in the url of your deploy page | ||
ids: [90210], // if your pageType is 'entity' this is required, and it is the uid of the entity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required on directory pages (or if it's optional, is there a benefit to providing it?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in sites, it's necessary to identify the directory entity, since directory pages are entity pages |
||
}); | ||
``` | ||
|
||
Now that the pages analytics reporter is initialized, we can fire a pageview: | ||
```ts | ||
pagesAnalytics.pageView(); | ||
``` | ||
|
||
We can also fire an event on any other type of user interaction and give it a custom name: | ||
```ts | ||
pagesAnalytics.userInteraction('somebuttonclick'); | ||
``` | ||
|
||
#### Search Analytics Event Types | ||
When specifying the analytics type, either the [AnalyticsEventType](./docs/analytics.analyticseventtype.md) enum | ||
or its corresponding string can be specified. For example, you can specify the 'CTA_CLICK' event with either 'CTA_CLICK' or | ||
with `AnalyticsEventType.CtaClick`. Once the event type is specified, TypeScript is able to enforce the required and | ||
optional properties for that event type. | ||
|
||
And that's it! See **[our documentation](./docs/analytics.md)** for a full list of analytics events. | ||
|
||
### Module support | ||
## Module support | ||
- The ESM (ES6) build will be used automatically by module bundlers that support it (e.g. Webpack). It can be specified directly by importing `@yext/analytics/lib/esm` | ||
- The CommonJS build will be used automatically by Node, but it can be specified directly by importing `@yext/analytics/lib/commonjs` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [featureId](./analytics.pagesanalyticsconfig.featureid.md) | ||
|
||
## PagesAnalyticsConfig.featureId property | ||
|
||
The identifier of the feature within the site, typically 'name' key of the feature in the features.json file | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
featureId: string; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [ids](./analytics.pagesanalyticsconfig.ids.md) | ||
|
||
## PagesAnalyticsConfig.ids property | ||
|
||
Yext Internal ID of Entities to Track | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
ids?: number[]; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) | ||
|
||
## PagesAnalyticsConfig interface | ||
|
||
The main configuration options for Pages Analytics | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface PagesAnalyticsConfig extends BaseAnalyticsConfig | ||
``` | ||
<b>Extends:</b> BaseAnalyticsConfig | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [featureId](./analytics.pagesanalyticsconfig.featureid.md) | string | The identifier of the feature within the site, typically 'name' key of the feature in the features.json file | | ||
| [ids?](./analytics.pagesanalyticsconfig.ids.md) | number\[\] | <i>(Optional)</i> Yext Internal ID of Entities to Track | | ||
| [pagesReferrer?](./analytics.pagesanalyticsconfig.pagesreferrer.md) | string | <i>(Optional)</i> The url the user came from will default to window.document.referrer | | ||
| [pageType](./analytics.pagesanalyticsconfig.pagetype.md) | 'entity' \| 'directory' \| 'locator' \| 'static' | Page Type The 'Page Type' filter found in analytics report builder Either entity, directory, locator, or static | | ||
| [path?](./analytics.pagesanalyticsconfig.path.md) | string | <i>(Optional)</i> The path component of the page url will default to window.location.pathname | | ||
| [product](./analytics.pagesanalyticsconfig.product.md) | 'storepages' \| 'sites' | The analytics ID of the version of pages 'storepages' for classic pages 'sites' for the latest version of the platform | | ||
| [production](./analytics.pagesanalyticsconfig.production.md) | boolean | Set to true if the environment is production If set to true events will appear in Analytics Reports in your Yext Account | | ||
| [siteId](./analytics.pagesanalyticsconfig.siteid.md) | number | The ID of the Pages Site Can be easily found from the url of the Deploy Page in your Yext Account e.g. https://www.yext.com/s/\[businessId\]/yextsites/\[siteid\]/branch/\[branchId\]/deploys/recent | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [pagesReferrer](./analytics.pagesanalyticsconfig.pagesreferrer.md) | ||
|
||
## PagesAnalyticsConfig.pagesReferrer property | ||
|
||
The url the user came from will default to window.document.referrer | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
pagesReferrer?: string; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [pageType](./analytics.pagesanalyticsconfig.pagetype.md) | ||
|
||
## PagesAnalyticsConfig.pageType property | ||
|
||
Page Type The 'Page Type' filter found in analytics report builder Either entity, directory, locator, or static | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
pageType: 'entity' | 'directory' | 'locator' | 'static'; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [path](./analytics.pagesanalyticsconfig.path.md) | ||
|
||
## PagesAnalyticsConfig.path property | ||
|
||
The path component of the page url will default to window.location.pathname | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
path?: string; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [product](./analytics.pagesanalyticsconfig.product.md) | ||
|
||
## PagesAnalyticsConfig.product property | ||
|
||
The analytics ID of the version of pages 'storepages' for classic pages 'sites' for the latest version of the platform | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
product: 'storepages' | 'sites'; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [production](./analytics.pagesanalyticsconfig.production.md) | ||
|
||
## PagesAnalyticsConfig.production property | ||
|
||
Set to true if the environment is production If set to true events will appear in Analytics Reports in your Yext Account | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
production: boolean; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) > [siteId](./analytics.pagesanalyticsconfig.siteid.md) | ||
|
||
## PagesAnalyticsConfig.siteId property | ||
|
||
The ID of the Pages Site Can be easily found from the url of the Deploy Page in your Yext Account e.g. https://www.yext.com/s/\[businessId\]/yextsites/\[siteid\]/branch/\[branchId\]/deploys/recent | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
siteId: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/analytics](./analytics.md) > [PagesAnalyticsService](./analytics.pagesanalyticsservice.md) | ||
|
||
## PagesAnalyticsService interface | ||
|
||
A service for reporting pages analytics events. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface PagesAnalyticsService | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [pageView()](./analytics.pagesanalyticsservice.pageview.md) | Reports a page view event. Will preform a promise rejection if the API contains an error or if the parameters are misconfigured. | | ||
| [userInteraction(eventName)](./analytics.pagesanalyticsservice.userinteraction.md) | Reports a user interaction event. Will perform a promis rejection if the API contains an error or if the parameters are misconfigured. | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're using the react code features.json is autogenerated and you may never look at it, might need to specify that the name in that case is taken from the file name of your entry template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack