Skip to content

chore: add helper script to auto update analytics #68

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 12 commits into from
Apr 14, 2025

Conversation

daniel-graham-amplitude

Added a new Node script, "node ./scripts/update-analytics-plugin", that will 1. prompt the user for a version number; 2. download and compress the analytics script from the CDN, with that version number; 3. write the contents to the "amplitude-wrapper.js"

I tested this by following this guide and then ran it on a local "ngrok" server. I had built analytics browser with version 2.11.11 and can confirm that it worked and could send an event to Amplitude from window.amplitudeGTM

Screenshot 2025-04-10 at 1 38 01 PM

(Also, this PR moved "downloadAndDecompress" to a re-usable helper function used by the two scripts)

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

scripts/update-sr-plugin.js:7

  • [nitpick] The variable 'pluginName' is declared but not used in the shown diff. Consider removing it if it is no longer required to reduce potential confusion.
const pluginName = 'sessionReplayPlugin';

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

scripts/update-sr-plugin.js:7

  • The variable 'pluginName' is defined but not used anywhere in this script; consider removing it to clean up the code.
const pluginName = 'sessionReplayPlugin';

scripts/helpers.js:4

  • Consider adding unit tests for the downloadAndDecompress helper to validate its behavior with various response scenarios, including error cases and proper decompression.
function downloadAndDecompress(url) {

@daniel-graham-amplitude daniel-graham-amplitude marked this pull request as draft April 10, 2025 21:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

scripts/update-analytics-plugin.js:20

  • Consider adding unit or integration tests for the update-analytics-plugin.js script to verify the version prompt, download, decompression process, and file update behavior.
(async () => {

@daniel-graham-amplitude daniel-graham-amplitude marked this pull request as ready for review April 10, 2025 21:02
@Mercy811
Copy link
Contributor

Thanks @daniel-graham-amplitude for adding it. But I just realized that we shouldn't replace it with https://cdn.amplitude.com/libs/analytics-browser-gtm-${version}-min.js.gz. The doc uses packages/analytics-browser/lib/scripts/amplitude-gtm-snippet-min.js. The snippet file is a script loader with with a amplitude client proxy.

iifeGTM
	input:	src/gtm-snippet-index.ts
	output:	
		lib/scripts/amplitude-gtm-min.js
		lib/scripts/amplitude-gtm-min.js.gz
			upload-to-s3.js -> https://cdn.amplitude.com/libs/analytics-browser-gtm-2.11.11-min.js.gz

snippetGTM
	input: 	generated/amplitude-gtm-snippet.js			<- defined in createGTMSnippet()
	output: lib/scripts/amplitude-gtm-snippet-min.js

To automate this, something we are missing

  • upload lib/scripts/amplitude-gtm-snippet-min.js to s3 with version name
  • pull it in update-analytics-plugin.js

@lewgordon-amplitude
Copy link
Collaborator

Nice! Glad to see this added, but I don't have full context what's required here for the browser SDK though.

@daniel-graham-amplitude
Copy link
Author

Nice! Glad to see this added, but I don't have full context what's required here for the browser SDK though.

No problem Lew. I just wanted to include you because you had done the session replay version of this.

Copy link
Contributor

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Dan! LGTM

@daniel-graham-amplitude daniel-graham-amplitude merged commit df4defa into v3.x Apr 14, 2025
1 check passed
@daniel-graham-amplitude daniel-graham-amplitude deleted the AMP-128318/auto-update-analytics-plugin branch April 14, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants