Skip to content

Commit 19e804f

Browse files
[Hot Fix] Gigs Referral Credit Feature (#70)
Hot Fix for milestone v1.2.0
1 parent 2c6760e commit 19e804f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/utils/referral.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,29 @@ ${makeGigReferralUrl(externalId, referralId)}`,
4040
],
4141
});
4242

43+
export const getHostDomain = () => {
44+
let hostDomain = "";
45+
if (location.hostname !== "localhost") {
46+
hostDomain =
47+
"." +
48+
location.hostname.split(".").reverse()[1] +
49+
"." +
50+
location.hostname.split(".").reverse()[0];
51+
}
52+
return hostDomain;
53+
};
54+
4355
/**
4456
* Sets the cookie with referral id.
4557
*/
4658
export const setReferralCookie = () => {
4759
const params = new URLSearchParams(location.search);
4860
const referralId = params.get("referralId");
4961
if (referralId) {
50-
cookies.set(
51-
process.env.GROWSURF_COOKIE,
52-
JSON.stringify({ referralId }),
53-
process.env.GROWSURF_COOKIE_SETTINGS
54-
);
62+
cookies.set(process.env.GROWSURF_COOKIE, JSON.stringify({ referralId }), {
63+
...process.env.GROWSURF_COOKIE_SETTINGS,
64+
domain: getHostDomain(),
65+
});
5566
}
5667
};
5768

@@ -61,6 +72,7 @@ export const setReferralCookie = () => {
6172
export const clearReferralCookie = () => {
6273
cookies.set(process.env.GROWSURF_COOKIE, "", {
6374
maxAge: 0,
75+
domain: getHostDomain(),
6476
overwrite: true,
6577
});
6678
};

0 commit comments

Comments
 (0)