@@ -289,18 +289,37 @@ export const redirect = (app: ReturnType<typeof next>): Handler => async (
289
289
return res . redirect ( "/banned" ) ;
290
290
}
291
291
292
- // 5. If wants to see link info, then redirect
292
+ // 5. Append query string when provided
293
+ if ( req . query ) {
294
+ const url = URL . parse ( link . target , true ) ;
295
+ const linkTargetParams = new URLSearchParams ( url . search ) ;
296
+
297
+ let added = 0 ;
298
+ Object . entries ( req . query ) . forEach ( ( [ key , value ] ) => {
299
+ if ( typeof value === "string" ) {
300
+ added ++ ;
301
+ linkTargetParams . append ( key , value ) ;
302
+ }
303
+ } ) ;
304
+
305
+ if ( added ) {
306
+ url . search = linkTargetParams . toString ( ) ;
307
+ link . target = URL . format ( url ) ;
308
+ }
309
+ }
310
+
311
+ // 6. If wants to see link info, then redirect
293
312
const doesRequestInfo = / .* \+ $ / gi. test ( req . params . id ) ;
294
313
if ( doesRequestInfo && ! link . password ) {
295
314
return app . render ( req , res , "/url-info" , { target : link . target } ) ;
296
315
}
297
316
298
- // 6 . If link is protected, redirect to password page
317
+ // 7 . If link is protected, redirect to password page
299
318
if ( link . password ) {
300
319
return res . redirect ( `/protected/${ link . uuid } ` ) ;
301
320
}
302
321
303
- // 7 . Create link visit
322
+ // 8 . Create link visit
304
323
if ( link . user_id && ! isBot ) {
305
324
queue . visit . add ( {
306
325
headers : req . headers ,
@@ -310,7 +329,19 @@ export const redirect = (app: ReturnType<typeof next>): Handler => async (
310
329
} ) ;
311
330
}
312
331
313
- // 8. Redirect to target
332
+ // 9. Create Google Analytics visit
333
+ if ( env . GOOGLE_ANALYTICS_UNIVERSAL && ! isBot ) {
334
+ ua ( env . GOOGLE_ANALYTICS_UNIVERSAL )
335
+ . pageview ( {
336
+ dp : `/${ address } ` ,
337
+ ua : req . headers [ "user-agent" ] ,
338
+ uip : req . realIP ,
339
+ aip : 1
340
+ } )
341
+ . send ( ) ;
342
+ }
343
+
344
+ // 10. Redirect to target
314
345
return res . redirect ( link . target ) ;
315
346
} ;
316
347
0 commit comments