Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from usherlabs/feature/permit-custom-api-url
Browse files Browse the repository at this point in the history
Permit custom API URL and remove `staging` parameter
  • Loading branch information
rsoury authored Apr 20, 2023
2 parents a5f3644 + 65b60c5 commit 4aed010
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ UsherJS can be instantiated by optionally passing a `config` object.
const usher = Usher();

// or
const usher2 = Usher({ staging: true });
const usher2 = Usher({ apiUrl: "https://app.staging.usher.so/api" });

// or
const usher3 = Usher({ apiUrl: "<YOUR_USHER_NODE_URL>/api" });
```

#### Options

|**Option**|**Type**|**Default**|**Description**
|----------|--------|-----------|---------------
|`staging`|boolean|false|A flag to indicate whether to use a [Staging Environment](https://app.staging.usher.so) for Testing/Integration Purposes, or the [Live Environment](https://app.usher.so)
|`apiUrl`|string|"https://app.usher.so/api"|The URL to the Usher API to use for Conversion Tracking
|`conflictStrategy`|string (enum)|"passthrough"|An enum to indicate how to handle conflicting tokens for the same campaign. The option can be either be `"passthrough"` or `"overwrite"`. In the "passthrough" scenario, referal tokens are backlogged for the same campaign. Any previously tracked referral token is saved to the browser until it expires or is used. In the "overwrite", any new referral token that is saved overwrites other saved tokens relative to the same campaign.

### Methods
Expand Down Expand Up @@ -116,7 +119,24 @@ usher.convert({

## 🧑‍💻 Testing Integration

To test your integration of UsherJS, be sure to configure using `Usher({ staging: true })` and then use one of the Test Campaigns over at the [Usher Staging Environment](https://app.staging.usher.so/)!
To test your integration of UsherJS, be sure to configure using `Usher({ apiUrl })`. You can use our [Usher Staging Environment](https://app.staging.usher.so/), or you can use your own Usher Node.

[Learn more on how to create an Usher Node →](https://github.com/usherlabs/usher)

### Testing with Usher Staging Environment

You may use our Staging Environment to test your integration of UsherJS. To do so, you will need to:

- Set the `apiUrl` option when instantiating UsherJS to `https://app.staging.usher.so/api`
- Use one of the Test Campaigns over at the [Usher Staging Environment](https://app.staging.usher.so/).


### Testing with other Usher Nodes

Another option is to use your own Usher Node. You can do so by setting the `apiUrl` option when instantiating UsherJS. To do so, you will need to:

- Set the `apiUrl` options when instantiating UsherJS to the URL of your Usher Node. (e.g. on local development: `http://localhost:3000/api`)


## 🐒 Development

Expand All @@ -136,3 +156,5 @@ yarn local

Then, make your changes and test them out using the [test Campaign on the Usher Staging Environment](https://app.staging.usher.so/campaign/arweave/ida4Pebl2uULdI_rN8waEw65mVH9uIFTY1JyeZt1PBM)!
This specific Test Campaign has a destination URL [http://localhost:3001/](http://localhost:3001/)

You may also use your own Usher node to develop.
13 changes: 6 additions & 7 deletions src/configure.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiUrl, stagingApiUrl } from "@/env-config";
import { apiUrl } from "@/env-config";
import { Config, ConflictStrategy } from "@/types";

class Configure {
Expand All @@ -15,12 +15,11 @@ class Configure {
}

public static use(config: Config) {
if (typeof config.staging === "boolean") {
if (config.staging === true) {
this._apiUrl = stagingApiUrl;
} else {
this._apiUrl = apiUrl;
}
// What api url will usher use?
// 1. If apiUrl is set by the user, use that
// 2. Otherwise, use the default apiUrl
if (typeof config.apiUrl === "string") {
this._apiUrl = config.apiUrl;
}
if (typeof config.conflictStrategy === "string") {
const strats = Object.values(ConflictStrategy);
Expand Down
1 change: 0 additions & 1 deletion src/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const appVersion = process.env.APP_VERSION;
export const appName = `${appPackageName}@${appVersion}`;

export const apiUrl = process.env.API_URL;
export const stagingApiUrl = process.env.STAGING_API_URL;

if (!apiUrl) {
console.log(`[USHER] ERROR: No API Url loaded!`);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum ConflictStrategy {
}

export type Config = {
staging?: boolean;
apiUrl?: string;
conflictStrategy?: ConflictStrategy;
};

Expand Down
2 changes: 1 addition & 1 deletion tools/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Hello Usher?</h1>
<script src="/build/index.js"></script>
<script>
var responseEl = document.querySelector("#response");
const usher = window.Usher({ staging: true })
const usher = window.Usher({ apiUrl: "https://app.staging.usher.so/api" })
responseEl.innerHTML += "<p>Yes, I'm here...</p>";
usher.anchor("#anchor-el", {
id: "ida4Pebl2uULdI_rN8waEw65mVH9uIFTY1JyeZt1PBM",
Expand Down

0 comments on commit 4aed010

Please sign in to comment.