Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Script from 'next/script';
import { INTERNXT_URL } from '@/constants';
import { useGlobalDialog } from '@/contexts/GlobalUIManager';
import { handleImpact } from '@/services/impact.service';
import { saveGclidToCookie } from '@/lib/cookies';
import { saveGclidToCookie, saveTrackingParamsToCookies } from '@/lib/cookies';

const slogan = {
en: "Internxt is a secure cloud storage service based on encryption and absolute privacy. Internxt's open-source suite of cloud storage services protects your right to privacy. Internxt Drive, Photos, Send, and more.",
Expand Down Expand Up @@ -55,6 +55,10 @@ export default function Layout({
saveGclidToCookie(gclid);
}

if (source) {
saveTrackingParamsToCookies();
}

if (source !== 'Impact') return;

handleImpact({
Expand Down
3 changes: 0 additions & 3 deletions src/components/layout/footers/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useEffect, useState } from 'react';
import { Transition, Disclosure } from '@headlessui/react';
import Link from 'next/link';
import setUTM from '@/lib/conversions';
import LanguageMobileBox from '../components/LanguageMobileBox';
import Image from 'next/image';
import axios from 'axios';
Expand Down Expand Up @@ -40,8 +39,6 @@ export default function Footer({
const year = moment().format('YYYY');

useEffect(() => {
setUTM();

axios.get(`${window.location.origin}/api/download`).then((res) => {
setPlatforms(res.data.platforms);
});
Expand Down
48 changes: 46 additions & 2 deletions src/lib/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ const GCLID_COOKIE_LIFESPAN_DAYS = 90;
const CELLO_EXPIRATION_DAYS = 30;
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;

const TRACKING_PARAMS = [
'utm_medium',
'utm_source',
'utm_campaign',
'utm_name',
'utm_id',
'gclid',
'irclickid',
'ga_campaign',
'ga_adgroup',
'ga_keyword',
'ga_network',
] as const;

function parseUri(ctx: GetServerSidePropsContext) {
const { query } = url.parse(ctx.req.url);
const parsedQuery = queryString.parse(query);
Expand All @@ -24,7 +38,7 @@ function setCookie({
cookieValue: string;
expiration?: Date;
}) {
const domain = process.env.NODE_ENV === 'production' ? 'internxt.com' : 'localhost';
const domain = process.env.NODE_ENV === 'production' ? '.internxt.com' : 'localhost';

const expirationDate = expiration ? new Date(expiration).toUTCString() : moment().add(100, 'days').toDate();

Expand Down Expand Up @@ -80,9 +94,38 @@ function setPublicCookie(ctx: GetServerSidePropsContext, name: string, value: st
export const saveGclidToCookie = (gclid: string) => {
const expiryDate = new Date();
expiryDate.setTime(expiryDate.getTime() + GCLID_COOKIE_LIFESPAN_DAYS * MILLISECONDS_PER_DAY);
document.cookie = `gclid=${gclid}; expires=${expiryDate.toUTCString()}; path=/`;
setCookie({
cookieName: 'gclid',
cookieValue: gclid,
expiration: expiryDate,
});
};

export const saveTrackingParamsToCookies = () => {
if (typeof window === 'undefined') return;

const params = new URLSearchParams(window.location.search);

const expiryDate = new Date();

expiryDate.setTime(
expiryDate.getTime() +
GCLID_COOKIE_LIFESPAN_DAYS * MILLISECONDS_PER_DAY,
);

TRACKING_PARAMS.forEach((param) => {
const value = params.get(param);

if (!value) return;

setCookie({
cookieName: param,
cookieValue: value,
expiration: expiryDate,
});
});
}

export const getGclidFromURL = (): string | null => {
if (typeof window === 'undefined') return null;
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -116,4 +159,5 @@ export default {
saveCelloFirstVisit,
getCelloFirstVisitDate,
isCelloExpired,
saveTrackingParamsToCookies
};
Loading