Skip to content

Commit

Permalink
Bugfix: don't incorrectly force utm_source to be hebcal.com
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Dec 8, 2024
1 parent c93dcd8 commit 1d3cdec
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 707 deletions.
908 changes: 219 additions & 689 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/rest-api",
"version": "6.0.2",
"version": "6.0.3",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal"
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"homepage": "https://hebcal.github.io/api/rest-api/",
"dependencies": {
"@hebcal/core": "^5.8.0",
"@hebcal/core": "^5.8.3",
"@hebcal/hdate": "^0.12.0",
"@hebcal/leyning": "^9.0.2"
},
Expand Down Expand Up @@ -59,8 +59,8 @@
"@types/jest": "^29.5.14",
"gts": "^5.3.1",
"jest": "^29.7.0",
"rollup": "^4.25.0",
"typedoc": "^0.26.11",
"typescript": "^5.6.3"
"rollup": "^4.28.1",
"typedoc": "^0.27.3",
"typescript": "^5.7.2"
}
}
8 changes: 7 additions & 1 deletion src/classic-rest-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export function eventToClassicApiObject(
}
const url = ev.url();
if (url) {
const utmSource = options.utmSource || 'js';
let utmSource = options.utmSource;
if (!utmSource) {
const u = new URL(url);
if (u.host === 'www.hebcal.com') {
utmSource = 'js';
}
}
const utmMedium = options.utmMedium || 'api';
const utmCampaign = options.utmCampaign;
result.link = appendIsraelAndTracking(
Expand Down
8 changes: 5 additions & 3 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ export function makeMemo(ev: Event, il: boolean): string {
export function appendIsraelAndTracking(
url: string,
il: boolean,
utmSource: string,
utmMedium: string,
utmSource?: string,
utmMedium?: string,
utmCampaign?: string
): string {
const u = new URL(url);
Expand Down Expand Up @@ -354,7 +354,9 @@ export function appendIsraelAndTracking(
return u.toString();
}
}
utmSource = isHebcal ? utmSource : 'hebcal.com';
if (!utmSource && !isHebcal) {
utmSource = 'hebcal.com'; // e.g. sefaria.org/foo?utm_source=hebcal.com
}
if (utmSource) {
u.searchParams.set('utm_source', utmSource);
}
Expand Down
4 changes: 3 additions & 1 deletion src/fullcalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function eventToFullCalendar(ev: Event, tzid: string, il: boolean): any {
}
const url = ev.url();
if (url) {
result.url = appendIsraelAndTracking(url, il, 'js', 'fc');
const u = new URL(url);
const utmSource = u.host === 'www.hebcal.com' ? 'js' : undefined;
result.url = appendIsraelAndTracking(url, il, utmSource, 'fc');
}
const desc = ev.getDesc();
const candles = desc === 'Havdalah' || desc === 'Candle lighting';
Expand Down
17 changes: 14 additions & 3 deletions src/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function getLinkAndGuid(
il: boolean,
tzid: string,
mainUrl: string,
utmSource: string,
utmMedium: string
utmSource?: string,
utmMedium?: string
): string[] {
let link;
let guid;
Expand Down Expand Up @@ -132,7 +132,18 @@ export function eventToRssItem2(ev: Event, options: RestApiOptions): string {
const location = options.location;
const il = location ? location.getIsrael() : false;
const tzid = location ? location.getTzid() : 'UTC';
const utmSource = options.utmSource || 'shabbat1c';
let utmSource = options.utmSource;
if (!utmSource) {
const url = ev.url();
if (url) {
const u = new URL(url);
if (u.host === 'www.hebcal.com') {
utmSource = 'shabbat1c';
}
} else {
utmSource = 'shabbat1c';
}
}
const utmMedium = options.utmMedium || 'rss';
const mainUrl = options.mainUrl || '';
const linkGuid = getLinkAndGuid(ev, il, tzid, mainUrl, utmSource, utmMedium);
Expand Down
22 changes: 17 additions & 5 deletions test/rss.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class MemoEvent extends Event {
}
// eslint-disable-next-line require-jsdoc
url() {
return 'http://localhost/';
return 'https://example.com/foo';
}
}

Expand All @@ -241,8 +241,8 @@ test('CDATA', () => {
const str = eventToRssItem2(ev, options);
expect(str).toBe(`<item>
<title>Hello World</title>
<link>http://localhost/?utm_source=hebcal.com&amp;utm_medium=rss</link>
<guid isPermaLink="false">http://localhost/#20210213-hello-world</guid>
<link>https://example.com/foo?utm_source=hebcal.com&amp;utm_medium=rss</link>
<guid isPermaLink="false">https://example.com/foo#20210213-hello-world</guid>
<description>Foo Bar</description>
<category>user</category>
<pubDate>Sat, 13 Feb 2021 00:00:00 GMT</pubDate>
Expand All @@ -253,8 +253,20 @@ test('CDATA', () => {
const str2 = eventToRssItem2(ev2, options);
expect(str2).toBe(`<item>
<title>Hello Two</title>
<link>http://localhost/?utm_source=hebcal.com&amp;utm_medium=rss</link>
<guid isPermaLink="false">http://localhost/#20210213-hello-two</guid>
<link>https://example.com/foo?utm_source=hebcal.com&amp;utm_medium=rss</link>
<guid isPermaLink="false">https://example.com/foo#20210213-hello-two</guid>
<description><![CDATA[<p>Baaz Quux</p>]]></description>
<category>user</category>
<pubDate>Sat, 13 Feb 2021 00:00:00 GMT</pubDate>
</item>
`);

const opts3 = {...options, utmSource: 'SHALOM'};
const str3 = eventToRssItem2(ev2, opts3);
expect(str3).toBe(`<item>
<title>Hello Two</title>
<link>https://example.com/foo?utm_source=SHALOM&amp;utm_medium=rss</link>
<guid isPermaLink="false">https://example.com/foo#20210213-hello-two</guid>
<description><![CDATA[<p>Baaz Quux</p>]]></description>
<category>user</category>
<pubDate>Sat, 13 Feb 2021 00:00:00 GMT</pubDate>
Expand Down

0 comments on commit 1d3cdec

Please sign in to comment.