Skip to content
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

Add events to Google Analytics with Node #245

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HrithikSampson
Copy link

@HrithikSampson HrithikSampson commented Oct 19, 2023

What does this PR do?

The function created will be triggered by configured Appwrite events and report these events to Google Analytics

Test Plan

I have checked the functionality by creating a dummy webapp and triggering event in Google Analytics by login and logout
Video Link: https://drive.google.com/file/d/1CONrh9BpSRaEv3JcdshtexRKQDRCUOU5/view?usp=sharing

Related PRs and Issues

Have you read the Contributing Guidelines on issues?

Yes

Copy link

@gewenyu99 gewenyu99 left a comment

Choose a reason for hiding this comment

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

Hey, great start, we need to refactor the code a bit to fit our code standards and make things easier to read. Thank you so much!

appwrite.json Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
@HrithikSampson HrithikSampson force-pushed the feat-events-to-ga-node branch 8 times, most recently from 93b4c47 to df0b4ef Compare October 21, 2023 12:50
@HrithikSampson
Copy link
Author

Hi @gewenyu99 I have changed the code and pushed the changes
Here I have again tested it : https://drive.google.com/file/d/1Sa8Z20OgK1jI9oj4IiI8ppWXkeFU-pAM/view?usp=sharing

Thanks for the review comments

"license": "ISC",
"dependencies": {
"node-appwrite": "^11.0.0",
"node-fetch": "^3.3.2",
Copy link
Member

@loks0n loks0n Oct 26, 2023

Choose a reason for hiding this comment

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

Can we use fetch from undici module?
You can see examples in other templates

Comment on lines 4 to 5
const ga4MeasurementId = process.env.GA4_MEASUREMENT_ID;
const ga4secret = process.env.GA4_API_SECRET;
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use these process.env inline? Just a style thing

Copy link

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

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

Great PR! 🤯 We left some comments during the review, please check them out.

node/events-to-ga/README.md Outdated Show resolved Hide resolved
node/events-to-ga/README.md Outdated Show resolved Hide resolved
node/events-to-ga/README.md Outdated Show resolved Hide resolved
node/events-to-ga/package.json Outdated Show resolved Hide resolved
node/events-to-ga/package.json Outdated Show resolved Hide resolved
node/events-to-ga/src/utils.js Outdated Show resolved Hide resolved
node/events-to-ga/src/utils.js Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
node/events-to-ga/src/main.js Outdated Show resolved Hide resolved
node/events-to-ga/src/utils.js Outdated Show resolved Hide resolved
@Haimantika
Copy link

Hi @HrithikSampson can you please work on the suggested changes and request a re-review by tomorrow? We can add the hacktoberfest-accepted label then

@HrithikSampson
Copy link
Author

Ok I will do it by tomorrow

@HrithikSampson HrithikSampson force-pushed the feat-events-to-ga-node branch 5 times, most recently from 692a880 to 2310fbb Compare October 31, 2023 12:30
@@ -0,0 +1,124 @@
<!-- Name your function -->
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the markdown comments like this?

import { fetch } from "undici";
import { verifyHeaders, formatIntoGoogleAnalyticsEvent } from "./utils.js";

/* Appwrite function */
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this comment?

/* Appwrite function */

export default async ({ res, req, log, error }) => {
// Listen for Appwrite events
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this comment?

*/
export function verifyHeaders(req) {
if (req.headers["x-appwrite-user-id"] == "") {
throw `x-appwrite-user-id value in req.headers is not there`;
Copy link
Member

Choose a reason for hiding this comment

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

Can you do throw new Error("...") here instead? and below

throw `x-appwrite-user-id value in req.headers is not there`;
}
if (req.headers["x-appwrite-trigger"] != "event") {
throw `Not triggered by event but by ${req.headers["x-appwrite-trigger"]}`;
Copy link
Member

Choose a reason for hiding this comment

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

Can you do throw new Error("...") here instead?

"undici": "^5.27.0"
},
"devDependencies": {
"prettier": "^3.0.3"
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add a .pretterrc.json with the same settings as other template?

node/events-to-ga/src/utils.js Outdated Show resolved Hide resolved
node/events-to-ga/src/utils.js Outdated Show resolved Hide resolved
Comment on lines 47 to 59
if (i % 2 == 0) oddElemArray.push(splitArray[i]);
else
wildCardArray.push([
`${oldElemArray[oldElemArray.length - 1]}Id`,
splitArray[i],
]);
Copy link
Member

Choose a reason for hiding this comment

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

Please add curly braces here, we prefer to use common syntax so the template is accessible

user_id: `${req.headers["x-appwrite-user-id"]}`,
events: [
{
// Event names must have all characters as alphanumeric.
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment necessary?

@HrithikSampson
Copy link
Author

Testing Video: https://drive.google.com/file/d/1Guw74H-xbZm1Xl2mlIlNBnMYVUBuhrAr/view?usp=sharing

Hi @Haimantika, I have requested for rereview

if (i % 2 == 0) oddElemArray.push(splitArray[i]);
else
wildCardArray.push([
`${oddElemArray[oddElemArray.length - 1]}Id`,

Choose a reason for hiding this comment

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

Hmm this will result in something like databasesId, right? It would be better if it was singular to match how we typically have it.

Choose a reason for hiding this comment

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

Also, this algorithm won't work for events like teams.*.memberships.*.update.status

Copy link
Author

Choose a reason for hiding this comment

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

is it because of no 's' in update because that I can resolve but I cant find out a way to get [status,prefs,name,email,password] unless I consider them that these will not go to the wildcard array

Copy link
Author

Choose a reason for hiding this comment

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

can I do that

Copy link
Author

Choose a reason for hiding this comment

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

Can I assume the length of the words in wildCard array is more than 12 or somethiing to distinguish it

Choose a reason for hiding this comment

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

is it because of no 's' in update because that I can resolve but I cant find out a way to get [status,prefs,name,email,password] unless I consider them that these will not go to the wildcard array

Because not every odd element is an ID. Although...I guess it's fine that status ends up in the params...

Choose a reason for hiding this comment

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

Can I assume the length of the words in wildCard array is more than 12 or somethiing to distinguish it

No, an ID isn't necessarily more than 12 chars.

@stnguyen90 stnguyen90 changed the title Feat events to ga node Add events to Google Analytics with Node Oct 31, 2023
@HrithikSampson
Copy link
Author

image

Copy link

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

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

Please see #245 (comment)

Copy link

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

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

@gewenyu99
Copy link

Hey there! There were a lot of big PRs during this Hacktoberfest, and we wanted to give everyone ample time to collaborate with our engineering team. If you were able to merge your PRs during October, amazing. If it’s still not merged, don’t worry about it either. Either way, we’ve got your Hacktoberfest swag minted and ready to ship.

Please comment with your Discord username here so we can contact you about your shipping information to deliver your Hacktoberfest swag.

@HrithikSampson
Copy link
Author

Hi,
my discord username is hrithik9619

@gewenyu99
Copy link

Be in touch soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants