-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add new package specific to Pro features (#2870)
* Pro: 🚧 Look at Pro as different package w/ imports * 🚧 Move over tests and remove extra deps in JS lib * ✅ Fix tests for CI * ➖ Remove unused deps * 🎨 Fix imports and remove commented code * 🎨 Update to match correct JS class syntax
- Loading branch information
1 parent
44e7b57
commit e148b5b
Showing
25 changed files
with
12,119 additions
and
9,508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @shepherdpro/pro-js | ||
|
||
## 0.0.3 | ||
|
||
### Patch Changes | ||
|
||
- Fix exports for published packages | ||
|
||
## 0.0.2 | ||
|
||
### Patch Changes | ||
|
||
- Improve types and reusing the Pro JS module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Shepherd Pro | ||
|
||
Unlock additional capabilities and more full featured Journeys. | ||
|
||
* **Customizable Tour Templates**: Pre-designed templates for different types of software that can be easily customized. | ||
* **Analytics Integration**: To track user engagement and effectiveness of the tours. | ||
* **Multi-Language Support**: For global reach and accessibility. | ||
* **User Behavior Tracking**: To understand how users interact with the tours and optimize accordingly. | ||
* **Integration Capabilities**: Easy integration with a wide range of web applications and software. | ||
* **Responsive Design**: Ensuring tours work seamlessly on all devices. | ||
* **Feedback Mechanisms**: Allowing users to provide feedback directly within the tours. | ||
* **Advanced Branching Logic**: For personalized tour experiences based on user actions or profiles. | ||
|
||
# Demo | ||
See Shepherd Live on our docs website by clicking on the image: | ||
<a href="https://blog.shepherdpro.com/demo"> | ||
<img | ||
src="https://blog.shepherdpro.com/img/demo.png" | ||
alt="Guide your users through a tour of your app" | ||
style="height: auto; max-width: 800px; width: 100%;"/> | ||
</a> | ||
|
||
## Install Directly | ||
|
||
```bash | ||
npm install @shepherdpro/pro-js --save | ||
``` | ||
|
||
```bash | ||
yarn add @shepherdpro/pro-js | ||
``` | ||
|
||
```bash | ||
pnpm add @shepherdpro/pro-js | ||
``` | ||
|
||
```bash | ||
bun add @shepherdpro/pro-js | ||
``` | ||
|
||
### Shepherd Pro hosted SaaS (Alpha) | ||
|
||
You can try our hosted version for free at [https://shepherdpro.com/](https://shepherdpro.com) | ||
|
||
The Entire Shepherd Service that powers Shepherd Pro is the newest iteration of Shepherd and includes the features of Shepherd Pro. | ||
|
||
# White Glove Services | ||
|
||
If you have an idea or project in mind and would like to engage our team to build a custom tour, training or on-boarding experience, get in touch! [hello@shepherdpro.com](mailto:hello@shepherdpro.com) | ||
|
||
## Resources | ||
|
||
- [Website](https://shepherdpro.com/) | ||
- [Documentation](https://docs.shepherdpro.com/) | ||
- [Demo](https://blog.shepherdpro.com/demo/) | ||
- If you have any questions about our projects you can email [hello@shepherdpro.com](mailto:hello@shepherdpro.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@shepherdpro/pro-js", | ||
"version": "0.0.3", | ||
"private": false, | ||
"main": "./dist/index.umd.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.umd.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "vite build", | ||
"test:ci": "vitest --run", | ||
"test:dev": "vitest" | ||
}, | ||
"devDependencies": { | ||
"@vitest/ui": "^1.6.0", | ||
"fake-indexeddb": "^5.0.2", | ||
"happy-dom": "^12.10.3", | ||
"vite": "^5.2.11", | ||
"vite-plugin-dts": "^3.7.1", | ||
"vitest": "^1.6.0" | ||
}, | ||
"dependencies": { | ||
"shepherd.js": "workspace:*", | ||
"idb": "^8.0.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import Shepherd, { ShepherdBase } from 'shepherd.js'; | ||
import type { TourOptions, EventOptions } from 'shepherd.js'; | ||
|
||
import DataRequest from './DataRequest'; | ||
import { getContext } from './utils/context.ts'; | ||
|
||
interface Actor { | ||
actorId: number; | ||
} | ||
|
||
const SHEPHERD_DEFAULT_API = 'https://shepherdpro.com' as const; | ||
const SHEPHERD_USER_ID = 'shepherdPro:userId' as const; | ||
|
||
class ProTour extends Shepherd.Tour { | ||
public events = ['active', 'cancel', 'complete', 'show']; | ||
|
||
private currentUserId: string | null = null; | ||
|
||
constructor(options?: TourOptions) { | ||
super(options); | ||
|
||
this.currentUserId = localStorage.getItem(SHEPHERD_USER_ID); | ||
|
||
const { dataRequester } = ShepherdProInstance; | ||
|
||
if (dataRequester) { | ||
this.trackedEvents.forEach((event) => | ||
this.on(event, (opts: EventOptions) => { | ||
const { tour } = opts; | ||
const { id, steps } = tour; | ||
let position; | ||
|
||
if (event !== 'active') { | ||
const { step: currentStep } = opts; | ||
|
||
if (currentStep) { | ||
position = | ||
steps.findIndex((step) => step.id === currentStep.id) + 1; | ||
} | ||
} | ||
|
||
const data = { | ||
currentUserId: this.currentUserId, | ||
eventType: event, | ||
journeyData: { | ||
id, | ||
currentStep: position, | ||
numberOfSteps: steps.length, | ||
tourOptions: tour.options | ||
} | ||
}; | ||
dataRequester?.sendEvents({ data }); | ||
}) | ||
); | ||
} | ||
} | ||
} | ||
|
||
export class ShepherdPro extends ShepherdBase { | ||
// Shepherd Pro fields | ||
apiKey?: string; | ||
apiPath?: string; | ||
dataRequester?: DataRequest; | ||
isProEnabled = false; | ||
/** | ||
* Extra properties to pass to Shepherd Pro App | ||
*/ | ||
properties?: { [key: string]: unknown }; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.Tour = ProTour; | ||
} | ||
|
||
/** | ||
* Call init to take full advantage of ShepherdPro functionality | ||
* @param {string} apiKey The API key for your ShepherdPro account | ||
* @param {string} apiPath | ||
* @param {object} properties Extra properties to be passed to Shepherd Pro | ||
*/ | ||
async init( | ||
apiKey?: string, | ||
apiPath?: string, | ||
properties?: { [key: string]: unknown } | ||
) { | ||
if (!apiKey) { | ||
throw new Error('Shepherd Pro: Missing required apiKey option.'); | ||
} | ||
|
||
this.apiKey = apiKey; | ||
this.apiPath = apiPath ?? SHEPHERD_DEFAULT_API; | ||
this.properties = properties ?? {}; | ||
this.properties['context'] = getContext(window); | ||
|
||
if (this.apiKey) { | ||
this.dataRequester = new DataRequest( | ||
this.apiKey, | ||
this.apiPath, | ||
this.properties | ||
); | ||
|
||
// Setup actor before first tour is loaded if none exists | ||
const shepherdProId = localStorage.getItem(SHEPHERD_USER_ID); | ||
|
||
const promises = [this.dataRequester.getTourState()]; | ||
|
||
if (!shepherdProId) { | ||
promises.push(this.createNewActor()); | ||
} | ||
|
||
await Promise.all(promises); | ||
} | ||
} | ||
|
||
async createNewActor() { | ||
if (!this.dataRequester) return; | ||
|
||
// Setup type returns an actor | ||
const response = (await this.dataRequester.sendEvents({ | ||
data: { | ||
currentUserId: null, | ||
eventType: 'setup' | ||
} | ||
})) as unknown as Actor; | ||
|
||
localStorage.setItem(SHEPHERD_USER_ID, String(response.actorId)); | ||
} | ||
|
||
/** | ||
* Checks if a given tour's id is enabled | ||
* @param tourId A string denoting the id of the tour | ||
*/ | ||
async isTourEnabled(tourId: string) { | ||
if (!this.dataRequester) return; | ||
|
||
const tourState = await this.dataRequester.tourStateDb?.get( | ||
'tours', | ||
tourId | ||
); | ||
|
||
return tourState?.isActive ?? true; | ||
} | ||
} | ||
|
||
const ShepherdProInstance = new ShepherdPro(); | ||
|
||
export default Object.assign(ShepherdProInstance, Shepherd) as ShepherdPro; |
File renamed without changes.
Oops, something went wrong.