Skip to content

Commit

Permalink
Remove support for regional TLDs (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Mar 17, 2023
1 parent 3ffc277 commit aa4d2cb
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/marketing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Marketing Build'

on:
push:
branches: [v503/reset-de]
branches: [v502/cookie]

jobs:
marketing:
Expand Down
8 changes: 7 additions & 1 deletion backend/src/db/actions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,19 @@ export async function associateUserWithAdWordsCampaign(
id: user.id,
},
});
if (userEntity && tracking.campaignId && tracking.creativeId) {
if (
userEntity &&
tracking.campaignId &&
tracking.creativeId &&
!userEntity.tracking.trackedAt
) {
userEntity.tracking = new TrackingEntity();
userEntity.tracking.campaignId = tracking.campaignId;
userEntity.tracking.creativeId = tracking.creativeId;
userEntity.tracking.device = tracking.device || null;
userEntity.tracking.keyword = tracking.keyword || null;
userEntity.tracking.gclid = tracking.gclid || null;
userEntity.tracking.trackedAt = new Date();
await userRepository.save(userEntity);
}
});
Expand Down
3 changes: 3 additions & 0 deletions backend/src/db/entities/TrackingEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ export default class TrackingEntity {
public keyword: string | null;
@Column({ nullable: true, type: 'character varying' })
public gclid: string | null;
@Column({ nullable: true, type: 'timestamp with time zone' })
public trackedAt: Date | null;

constructor() {
this.campaignId = null;
this.creativeId = null;
this.device = null;
this.keyword = null;
this.gclid = null;
this.trackedAt = null;
}
}
14 changes: 14 additions & 0 deletions backend/src/db/migrations/1679043892889-tracked-at.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class trackedAt1679043892889 implements MigrationInterface {
name = 'trackedAt1679043892889'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users" ADD "tracking_tracked_at" TIMESTAMP WITH TIME ZONE`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "tracking_tracked_at"`);
}

}
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ db().then(() => {

app.get('/api/me', async (req, res) => {
const user = await getUserViewFromRequest(req);
const trackingString: string = req.cookies['retro-aw-tracking'];
const trackingString: string = req.cookies['retro_aw'];
if (trackingString && user) {
const tracking: Partial<TrackingInfo> = JSON.parse(trackingString);
// We don't await this because we don't want to block the response
Expand Down
3 changes: 2 additions & 1 deletion marketing/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ NEXT_PUBLIC_APP_URL=http://localhost:3000
NEXT_PUBLIC_MEASUREMENT_ID=G-XXXXXXXXXX
NEXT_PUBLIC_GOOGLE_AD_WORDS_ID=AW-XXXXXXXXXX
NEXT_PUBLIC_GOOGLE_AD_WORDS_CONVERSION_ID=AW-XXXXXXXXXX/XXXXXXXXXX
NEXT_PUBLIC_GOOGLE_AD_WORDS_DOMAINS=foo.com,bar.com
NEXT_PUBLIC_GOOGLE_AD_WORDS_DOMAINS=foo.com,bar.com
NEXT_PUBLIC_COOKIE_DOMAIN=.retrospected.com
2 changes: 1 addition & 1 deletion marketing/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ARG NEXT_PUBLIC_APP_URL=APP_NEXT_PUBLIC_APP_URL
ARG NEXT_PUBLIC_GOOGLE_AD_WORDS_ID=APP_NEXT_PUBLIC_GOOGLE_AD_WORDS_ID
ARG NEXT_PUBLIC_GOOGLE_AD_WORDS_CONVERSION_ID=APP_NEXT_PUBLIC_GOOGLE_AD_WORDS_CONVERSION_ID
ARG NEXT_PUBLIC_GOOGLE_AD_WORDS_DOMAINS=APP_NEXT_PUBLIC_GOOGLE_AD_WORDS_DOMAINS
ARG NEXT_BACKEND_SUB_DOMAIN=APP_NEXT_BACKEND_SUB_DOMAIN
ARG NEXT_PUBLIC_COOKIE_DOMAIN=APP_NEXT_PUBLIC_COOKIE_DOMAIN
RUN yarn build

# If using npm comment out above and use below instead
Expand Down
1 change: 0 additions & 1 deletion marketing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ run:
docker run \
--env NEXT_PUBLIC_MEASUREMENT_ID=G-BLAH \
--env NEXT_PUBLIC_APP_URL=http://localhost:3000 \
--env NEXT_BACKEND_SUB_DOMAIN=www-beta \
-it --rm -p 3333:3000 retrospected/marketing:local
18 changes: 1 addition & 17 deletions marketing/next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
const subDomain = process.env.NEXT_BACKEND_SUB_DOMAIN;

module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr', 'de'], // , 'de', 'nl'],
domains: [
{
domain: `${subDomain}.retrospected.com`,
defaultLocale: 'en',
},
{
domain: `${subDomain}.retrospected.fr`,
defaultLocale: 'fr',
},
{
domain: `${subDomain}.retrospected.de`,
defaultLocale: 'de',
}
],
locales: ['en', 'fr', 'de'],
},
}
12 changes: 4 additions & 8 deletions marketing/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import parse from 'url-parse';

// https://www.retrospected.com/?campaignid=19686942887&creative=648178043912&device=c&keyword=retro

const COOKIE_NAME = 'retro-aw-tracking';
const COOKIE_NAME = 'retro_aw';

export type TrackingInfo = {
campaignId: string;
Expand Down Expand Up @@ -33,16 +33,12 @@ export function middleware(request: NextRequest) {
const cookie: ResponseCookie = {
name: COOKIE_NAME,
value: JSON.stringify(tracking),
sameSite: 'lax',
expires: addYears(new Date(), 1),
domain:
host.includes('localhost') || host.split('.').length < 3
? undefined
: host.split('.').slice(1).join('.'),
domain: host.includes('localhost')
? undefined
: process.env.NEXT_PUBLIC_COOKIE_DOMAIN,
};

console.log('tracking', tracking);

response.cookies.set(cookie);
}

Expand Down

0 comments on commit aa4d2cb

Please sign in to comment.