Skip to content

Commit

Permalink
Merge pull request #2 from yetric/support-plausible
Browse files Browse the repository at this point in the history
Add support for source and ref as well as utm_source (Plausible)
  • Loading branch information
hising authored Jan 9, 2024
2 parents 2f279e9 + 46adedb commit af668d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "use-utm",
"version": "1.0.2",
"description": "React hook for getting UTM parameters from the URL",
"version": "1.0.3",
"description": "Small library for getting/setting and removing UTM parameters from the URL",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions src/utm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ describe("useUtm", () => {
expect(campaign).toBeUndefined();
});

it("should be able to parse ref as source", () => {
const urlWithRef = "https://www.example.com/?ref=google";
const { source } = utm(urlWithRef);
expect(source).toEqual("google");
});

it("should be able to parse source as source", () => {
const urlWithSource = "https://www.example.com/?source=google";
const { source } = utm(urlWithSource);
expect(source).toEqual("google");
});

it("Should add utm params to a url", () => {
const url = "https://www.example.com/";
const utmParams = {
Expand Down
2 changes: 1 addition & 1 deletion src/utm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type MarketingParams = {
export const utm = (url: string): MarketingParams => {
const urlObject = new URL(url);
const urlParams = new URLSearchParams(urlObject.search);
const utmSource = urlParams.get("utm_source");
const utmSource = urlParams.get("utm_source") || urlParams.get("source") || urlParams.get("ref");
const utmMedium = urlParams.get("utm_medium");
const utmCampaign = urlParams.get("utm_campaign");
const utmTerm = urlParams.get("utm_term");
Expand Down

0 comments on commit af668d2

Please sign in to comment.