-
Notifications
You must be signed in to change notification settings - Fork 2
feat(user): add UTM parameters support in user creation and sign-up #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a757684
feat(user): add UTM parameters support in user creation and sign-up
Dobrunia ece94f6
Bump version up to 1.1.30
github-actions[bot] a4a7903
docs(user): clarify UTM parameter description in user creation and si…
Dobrunia 9ab01e5
chore(deps): update @hawk.so/types to version 0.1.33 and enhance user…
Dobrunia 33087ee
feat(user): validate and sanitize UTM parameters during user creation
Dobrunia 14dc023
feat(analytics): enhance UTM parameter validation to include object t…
Dobrunia 31ff97d
refactor(analytics): improve readability of UTM parameter validation …
Dobrunia e6a179f
refactor(utm): move UTM parameter validation and sanitization to a de…
Dobrunia c4aceeb
refactor(utm): add tests for UTM validation
Dobrunia bd6d64a
refactor(utm): extract UTM key validation and character checks into c…
Dobrunia 02376ca
refactor(utm): define maximum UTM value length as a constant for bett…
Dobrunia e8114da
refactor(utm): enhance UTM parameter validation to return detailed re…
Dobrunia 64b7122
chore(package): bump version to 1.1.32
Dobrunia 6ff0955
Merge branch 'master' into feat/utm-tags-integration
Dobrunia c9e37d7
fix lint
Dobrunia 4c6496e
fix lint
Dobrunia 7febc31
refactor(utm): streamline UTM parameter sanitization and improve erro…
Dobrunia 5d3ee35
test(utm): update UTM parameter validation tests to check for valid a…
Dobrunia e67f815
refactor(utm): simplify UTM parameter handling by removing sanitizati…
Dobrunia 271e380
fix
Dobrunia 34ea138
feat(users): add conditional UTM parameter inclusion in user data and…
Dobrunia 61a95fd
test(utm): update validation tests to return undefined for null and n…
Dobrunia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { UserDBScheme } from '@hawk.so/types'; | ||
|
|
||
| /** | ||
| * Validates UTM parameters | ||
| * @param utm - Data form where user went to sign up. Used for analytics purposes | ||
| * @returns boolean - true if valid, false if invalid | ||
| */ | ||
| export function validateUtmParams(utm: UserDBScheme['utm']): boolean { | ||
| if (!utm) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check if utm is an object | ||
| if (typeof utm !== 'object' || Array.isArray(utm)) { | ||
| return false; | ||
| } | ||
|
|
||
| const utmKeys = ['source', 'medium', 'campaign', 'content', 'term']; | ||
| const providedKeys = Object.keys(utm); | ||
|
|
||
| // Check if utm object is not empty | ||
| if (providedKeys.length === 0) { | ||
| return true; // Empty object is valid | ||
| } | ||
|
|
||
| // Check if all provided keys are valid UTM keys | ||
| const hasInvalidKeys = providedKeys.some((key) => !utmKeys.includes(key)); | ||
| if (hasInvalidKeys) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check if values are strings and not too long | ||
| for (const [key, value] of Object.entries(utm)) { | ||
| if (value !== undefined && value !== null) { | ||
| if (typeof value !== 'string') { | ||
| return false; | ||
| } | ||
|
|
||
| // Check length | ||
| if (value.length === 0 || value.length > 200) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check for valid characters - only allow alphanumeric, spaces, hyphens, underscores, dots | ||
| if (!/^[a-zA-Z0-9\s\-_.]+$/.test(value)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Sanitizes UTM parameters by removing invalid characters | ||
| * @param utm - Data form where user went to sign up. Used for analytics purposes | ||
| * @returns sanitized UTM parameters or undefined if invalid | ||
| */ | ||
| export function sanitizeUtmParams(utm: UserDBScheme['utm']): UserDBScheme['utm'] { | ||
| if (!utm) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const utmKeys = ['source', 'medium', 'campaign', 'content', 'term']; | ||
| const sanitized: UserDBScheme['utm'] = {}; | ||
|
|
||
| for (const [key, value] of Object.entries(utm)) { | ||
| if (utmKeys.includes(key) && value && typeof value === 'string') { | ||
| // Sanitize value: keep only allowed characters and limit length | ||
| const cleanValue = value | ||
| .replace(/[^a-zA-Z0-9\s\-_.]/g, '') | ||
neSpecc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .trim() | ||
| .substring(0, 200); | ||
|
|
||
| if (cleanValue.length > 0) { | ||
| (sanitized as any)[key] = cleanValue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Object.keys(sanitized).length > 0 ? sanitized : undefined; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.