-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
User turnstile event #6980
Merged
Merged
User turnstile event #6980
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d377f69
Ajax POST helper
ddb9898
Send a user Turnstile event anytime a TilJSON is used with mapbox til…
e0cfc97
Unit tests for Mapbox#postTurnstileEvent
82c0e58
Include mapbox.cn endpoints
d96e5fd
Update jsdom to 11.11.0 to get rid of 'Error: Cross origin null forbi…
790694e
Address commments from review
ccde5c7
Use a queue and in-memory state to ensure that multiple events are no…
9c8fd96
Error-ed requests should clear pending variables. Stop processing req…
2c25dd8
Consider access token change as a new user to support iFrame/embed us…
ab94794
Segment locally stored data by access token to allow multiple embeds …
b0e18e4
Add unit tests with mock LocalStorage
749ec7a
Expose TurnstileEvent class and fixup tests to be independent of order.
f92adfc
Fix tests
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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import UnitBezier from '@mapbox/unitbezier'; | |
|
||
import Coordinate from '../geo/coordinate'; | ||
import Point from '@mapbox/point-geometry'; | ||
import window from './window'; | ||
|
||
import type {Callback} from '../types/callback'; | ||
|
||
|
@@ -196,6 +197,27 @@ export function uniqueId(): number { | |
return id++; | ||
} | ||
|
||
/** | ||
* Return a random UUID (v4). Taken from: https://gist.github.com/jed/982883 | ||
*/ | ||
export function uuid(): string { | ||
function b(a) { | ||
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : | ||
//$FlowFixMe: Flow doesn't like the implied array literal conversion here | ||
([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b); | ||
} | ||
return b(); | ||
} | ||
|
||
/** | ||
* Validate a string to match UUID(v4) of the | ||
* form: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx | ||
* @param str string to validate. | ||
*/ | ||
export function validateUuid(str: ?string): boolean { | ||
return str ? /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str) : false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flow complaints that
|
||
} | ||
|
||
/** | ||
* Given an array of member function names as strings, replace all of them | ||
* with bound versions that will always refer to `context` as `this`. This | ||
|
@@ -440,3 +462,14 @@ export function parseCacheControl(cacheControl: string): Object { | |
|
||
return header; | ||
} | ||
|
||
export function storageAvailable(type: string): boolean { | ||
try { | ||
const storage = window[type]; | ||
storage.setItem('_mapbox_test_', 1); | ||
storage.removeItem('_mapbox_test_'); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the expected behavior if localStorage is not available? As of now, it looks like we'd only send a turnstile event once per page in that case, since
lastSuccess
would never be set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventData
caches the id and success values within a single session. But I see the problem, this value needs to be updated irrespective oflocalStorageAvailable
when a request succeeds.If
localStorage
is not available, there may be more than one event sent per calendar day, but the events server de-duplicates those.