-
Notifications
You must be signed in to change notification settings - Fork 230
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
Lite ATI Analytics script #12053
Merged
Merged
Lite ATI Analytics script #12053
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6df3da3
Lite ATI Analytics script
amoore108 2efc71b
Merge branch 'latest' into lite-atianalytics-script
amoore108 8456020
Merge branch 'latest' into lite-atianalytics-script
amoore108 81e87b6
Merge branch 'latest' into lite-atianalytics-script
amoore108 79253df
Merge branch 'latest' into lite-atianalytics-script
amoore108 9536fb6
Merge branch 'latest' into lite-atianalytics-script
amoore108 6822fa0
Merge branch 'latest' into lite-atianalytics-script
amoore108 9fbfb27
Merge branch 'latest' into lite-atianalytics-script
amoore108 036d4db
Merge branch 'latest' into lite-atianalytics-script
amoore108 c15a183
Merge branch 'latest' into lite-atianalytics-script
amoore108 cb94ab5
Separate Lite beacon into own file
amoore108 c26ce42
Merge branch 'latest' into lite-atianalytics-script
amoore108 f6b21a6
Merge branch 'latest' into lite-atianalytics-script
amoore108 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
35 changes: 35 additions & 0 deletions
35
src/app/components/ATIAnalytics/canonical/sendBeaconLite.test.ts
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-eval */ | ||
import sendBeaconLite from './sendBeaconLite'; | ||
|
||
let XMLHttpRequestSpy: jest.SpyInstance<XMLHttpRequest | undefined, []>; | ||
|
||
describe('sendBeaconLite', () => { | ||
const XMLHttpRequestMock: Partial<XMLHttpRequest> = { | ||
open: jest.fn(), | ||
withCredentials: false, | ||
send: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
XMLHttpRequestSpy = jest.spyOn(window, 'XMLHttpRequest'); | ||
}); | ||
|
||
afterEach(() => { | ||
XMLHttpRequestSpy.mockRestore(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should send beacon with XHR', () => { | ||
XMLHttpRequestSpy.mockImplementation( | ||
() => XMLHttpRequestMock as XMLHttpRequest, | ||
); | ||
|
||
eval(sendBeaconLite('https://foobar.com')); | ||
|
||
expect(XMLHttpRequestMock.open).toHaveBeenCalledWith( | ||
'GET', | ||
'https://foobar.com', | ||
true, | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const sendBeaconLite = (atiPageViewUrlString: string) => ` | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "${atiPageViewUrlString}", true); | ||
xhr.withCredentials = true; | ||
xhr.send(); | ||
`; | ||
|
||
export default sendBeaconLite; |
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.
Just thinking out loud here... what happens if the user views the lite site on opera mini? 😰
I think we're OK, but just wanted to check.
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.
It should be ok. The Lite script is basically identical to the Opera Mini script, so they'll get the same behaviour.
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.
And there's no danger of analytics being sent twice?
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.
This may be something we'll need to test on Opera Mini.
It was hard to diagnose at the time with the duplicate events, but my theory was that React hydration played a part with react-helmet. The way it behaves is it renders on the server once, then remounts the
<Helmet>
tags again on hydration. Lite skips out hydration, so in theory it shouldn't.Its just hard to know how Opera Mini servers behave with this though.
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.
We could literally do the exact same thing as we've done with Opera Mini and track if its been sent already in the
window
object. I don't think there is a problem with that on Lite, so maybe to be absolutely sure, we just copy the Opera Mini implementation?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.
Yeah that would work. I had thought that we might be able to consolidate both opera mini & lite implementations into a single script, but I think that would make things too complicated (and it is already complicated enough! 😰 )
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.
Yea I'd prefer to keep them separate even if they're almost the same. The Lite version may be extended in the future to handle click events too.