Skip to content
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

Merged
merged 25 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3720e93
feat(store_pagespixel): add legacy analytics support
tatimblin Jul 15, 2022
720ffd5
wip, having trouble with jest locally
benmcginnis Jul 22, 2022
ef25a23
Automated update to repo's documentation from github action
github-actions[bot] Jul 22, 2022
5152ee8
add tests but they are not working
benmcginnis Jul 22, 2022
e462922
test working
benmcginnis Jul 25, 2022
52da3a9
implement remaining test permutations for pages analytics reporter
benmcginnis Jul 25, 2022
131c0b4
update analyticsProvider to be more of a factory
benmcginnis Jul 25, 2022
cd0de3d
refactor to create separate providers for the three types of analytics
benmcginnis Jul 25, 2022
0e9db59
update readme
benmcginnis Jul 26, 2022
00ddf38
update readme some more
benmcginnis Jul 26, 2022
231f6b3
fix jsdoc errors and add some todos
benmcginnis Jul 26, 2022
d1d1f15
Automated update to repo's documentation from github action
github-actions[bot] Jul 26, 2022
4cff913
complete refactor based on spec feedback
benmcginnis Jul 28, 2022
fcbe05c
Automated update to repo's documentation from github action
github-actions[bot] Jul 28, 2022
8281ae5
update readme and add pageType param after conversation with peralta
benmcginnis Jul 28, 2022
6c0f271
Automated update to repo's documentation from github action
github-actions[bot] Jul 28, 2022
f5a355c
address tom's comments
benmcginnis Jul 28, 2022
3ca3bb2
Automated update to repo's documentation from github action
github-actions[bot] Jul 28, 2022
4c433ca
fix final tom comment and link in readme
benmcginnis Jul 28, 2022
fe36c0d
Automated update to repo's documentation from github action
github-actions[bot] Jul 28, 2022
b04b0e7
fix imports
benmcginnis Jul 28, 2022
b160906
make debug optional so as to not change the api
benmcginnis Jul 28, 2022
8dd1ecf
update test site and fix issues found during manual testing
benmcginnis Jul 28, 2022
5c4d583
Automated update to repo's documentation from github action
github-actions[bot] Jul 28, 2022
03a6734
make debugging work on search events
benmcginnis Jul 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 77 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

pageType: 'locator', // the type of page, can be 'entity', 'directory', 'locator', or 'static'
product: 'storepages',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should product be? If it's always storepages, is there a reason they need to specify it?

production: false, // set to true if you are in the production environment

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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',
Expand All @@ -59,15 +102,41 @@ analytics.report({
});
```

### Analytics Event Types
### Pages Analytics

```ts
import {providePagesAnalytics} from '@yext/analytics';

const pagesAnalytics = providePagesAnalytics({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include the path or pagesReferrer properties here?

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

Choose a reason for hiding this comment

The 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?)

Copy link
Member

Choose a reason for hiding this comment

The 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`

Expand Down
15 changes: 3 additions & 12 deletions docs/analytics.analyticsconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@

## AnalyticsConfig interface

The main configuration options for Analytics.
Combined Analytics Config for tracking Search &amp; Pages on the same site

<b>Signature:</b>

```typescript
export interface AnalyticsConfig
export interface AnalyticsConfig extends SearchAnalyticsConfig, PagesAnalyticsConfig
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [businessId](./analytics.analyticsconfig.businessid.md) | number | The businessId of the answers experience. |
| [domain?](./analytics.analyticsconfig.domain.md) | string | <i>(Optional)</i> The domain to send the requests to. |
| [experienceKey](./analytics.analyticsconfig.experiencekey.md) | string | The experience key of the answers experience. |
| [experienceVersion](./analytics.analyticsconfig.experienceversion.md) | 'PRODUCTION' \| 'STAGING' \| string | The experience version of the answers experience. |
| [visitor?](./analytics.analyticsconfig.visitor.md) | [Visitor](./analytics.visitor.md) | <i>(Optional)</i> Information used to associate analytics with a particular user. |
<b>Extends:</b> [SearchAnalyticsConfig](./analytics.searchanalyticsconfig.md)<!-- -->, [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md)

12 changes: 3 additions & 9 deletions docs/analytics.analyticsservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@

## AnalyticsService interface

A service for reporting analytics events.
A service for reporting both pages and search analytics events.

<b>Signature:</b>

```typescript
export interface AnalyticsService
export interface AnalyticsService extends SearchAnalyticsService, PagesAnalyticsService
```

## Methods

| Method | Description |
| --- | --- |
| [report(event, additionalRequestAttributes)](./analytics.analyticsservice.report.md) | Reports an analytics event. Will perform a promise rejection if the API response contains an error. |
| [setVisitor(visitor)](./analytics.analyticsservice.setvisitor.md) | Sets the [Visitor](./analytics.visitor.md) object which is included with each subsequent request. |
<b>Extends:</b> [SearchAnalyticsService](./analytics.searchanalyticsservice.md)<!-- -->, [PagesAnalyticsService](./analytics.pagesanalyticsservice.md)

21 changes: 17 additions & 4 deletions docs/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## analytics package

## Classes

| Class | Description |
| --- | --- |
| [PagesEventDetails](./analytics.pageseventdetails.md) | A fully detailed Pages Event |

## Enumerations

| Enumeration | Description |
Expand All @@ -14,22 +20,29 @@

| Function | Description |
| --- | --- |
| [provideAnalytics(config)](./analytics.provideanalytics.md) | The entrypoint to the analytics library. |
| [provideAnalytics(config)](./analytics.provideanalytics.md) | Provides a combined Pages &amp; Search Analytics service given a joint config |
| [providePagesAnalytics(config)](./analytics.providepagesanalytics.md) | Provides a combined Pages Analytics service given a Pages specific config |
| [provideSearchAnalytics(config)](./analytics.providesearchanalytics.md) | Provides a combined Search Analytics service given a Search specific config |

## Interfaces

| Interface | Description |
| --- | --- |
| [AccordionToggleEvent](./analytics.accordiontoggleevent.md) | Event for expanding or collapsing an accordion row. Commonly used for FAQs. |
| [AllTabNavigationEvent](./analytics.alltabnavigationevent.md) | Event for navigating to the 'all' tab (a universal page). |
| [AnalyticsConfig](./analytics.analyticsconfig.md) | The main configuration options for Analytics. |
| [AnalyticsConfig](./analytics.analyticsconfig.md) | Combined Analytics Config for tracking Search &amp; Pages on the same site |
| [AnalyticsPayload](./analytics.analyticspayload.md) | The shape of the data which is sent during an analytics request. |
| [AnalyticsService](./analytics.analyticsservice.md) | A service for reporting analytics events. |
| [AnalyticsService](./analytics.analyticsservice.md) | A service for reporting both pages and search analytics events. |
| [AutocompleteEvent](./analytics.autocompleteevent.md) | Event for autocomplete selection. |
| [CtaEvent](./analytics.ctaevent.md) | A call to action analytics event. |
| [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) | The main configuration options for Pages Analytics |
| [PagesAnalyticsService](./analytics.pagesanalyticsservice.md) | A service for reporting pages analytics events. |
| [PagesEvent](./analytics.pagesevent.md) | An event from the Pages system |
| [PaginationEvent](./analytics.paginationevent.md) | Event for pagination interaction. |
| [QuestionSubmissionEvent](./analytics.questionsubmissionevent.md) | Event for submitting a question. |
| [ScrollEvent](./analytics.scrollevent.md) | Event for scrolling to the bottom of the page. |
| [SearchAnalyticsConfig](./analytics.searchanalyticsconfig.md) | The main configuration options for Search Analytics. |
| [SearchAnalyticsService](./analytics.searchanalyticsservice.md) | A service for reporting search analytics events. |
| [SearchBarImpressionEvent](./analytics.searchbarimpressionevent.md) | Event for expanding or collapsing an accordion row. |
| [SearchClearEvent](./analytics.searchclearevent.md) | Event for clicking on the button to clear the search input. |
| [SearchDurationEvent](./analytics.searchdurationevent.md) | Event used to calculate the duration of a search. |
Expand All @@ -43,7 +56,7 @@

| Type Alias | Description |
| --- | --- |
| [AnalyticsEvent](./analytics.analyticsevent.md) | An analytics event. |
| [EnumOrString](./analytics.enumorstring.md) | A TypeScript utility type which creates a union of an enum member and its string representation. |
| [SearchAnalyticsEvent](./analytics.searchanalyticsevent.md) | An analytics event. |
| [Searcher](./analytics.searcher.md) | Whether the search occurred on universal or vertical search. |

13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.featureid.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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;
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.ids.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [ids](./analytics.pagesanalyticsconfig.ids.md)

## PagesAnalyticsConfig.ids property

Yext Internal ID of Entities to Track

<b>Signature:</b>

```typescript
ids?: number[];
```
28 changes: 28 additions & 0 deletions docs/analytics.pagesanalyticsconfig.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [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 |

13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.pagesreferrer.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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;
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.pagetype.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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';
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.path.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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;
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.product.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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';
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.production.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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;
```
13 changes: 13 additions & 0 deletions docs/analytics.pagesanalyticsconfig.siteid.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [PagesAnalyticsConfig](./analytics.pagesanalyticsconfig.md) &gt; [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;
```
21 changes: 21 additions & 0 deletions docs/analytics.pagesanalyticsservice.md
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) &gt; [@yext/analytics](./analytics.md) &gt; [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. |

Loading