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

Ga4/prod #173

Merged
merged 21 commits into from
Dec 21, 2020
Merged

Ga4/prod #173

merged 21 commits into from
Dec 21, 2020

Conversation

Shivam4415
Copy link
Contributor

@Shivam4415 Shivam4415 commented Dec 17, 2020

Description of the change

Description here

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Fix #1

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers mentioned in a comment
  • Changes have been reviewed by at least one other engineer
  • Issue from task tracker has a link to this pull request

This change is Reviewable

}
/* utility functions --- Ends here --- */

isReservedName(eventName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add the helper methods to GA4/utils ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

window.gtag("event", event, props);
}

getDestinationEvent(event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this too to utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return eventName.find((p) => p.src.includes(event.toLowerCase()));
}

getDestinationEventProperties(props, destParameter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor

Choose a reason for hiding this comment

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

As method doc like what is the input and output format with an example

Copy link
Contributor

Choose a reason for hiding this comment

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

better to use a library that does this? can you check once like get-value we use for transformer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

better to use a library that does this? can you check once like get-value we use for transformer?

There is a library : " loadash " using that we can do, but loading some external library means loading extra js, isn't if we use our own implementation where we can modify code as required. which means we can move above function to global and make more generic. One of the way I can think is going through loadash code and provide same implementation in our utils.
What do you say, should I use external library or implement on our own .....

Copy link
Contributor

Choose a reason for hiding this comment

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

we won't be loading a js but yes our total JS SDK size will increase. We can leave it
Can you add the examples for the input and output like
/*
props: {key: val, key2:val2}
destParameter: {..}
output: {...}
*/
getDestinationEventProperties(props, destParameter) {...}

return destinationProperties;
}

getDestinationItemProperties(products, item) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"Google Analytics 4": "GA4",
GoogleAnalytics4: "GA4",
GA4: "GA4",
>>>>>>> 23bdbcd... GA4 sdk implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

resolve conflict

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -20,8 +20,12 @@ const clientToServerNames = {
OPTIMIZELY: "Optimizely",
FULLSTORY: "Fullstory",
TVSQUUARED: "TVSquared",
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

resolve conflict

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

window.gtag(
"event",
"page_view",
(rudderElement.message.context && rudderElement.message.context.page) ||
Copy link
Contributor

@sayan-mitra sayan-mitra Dec 17, 2020

Choose a reason for hiding this comment

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

https://support.google.com/analytics/answer/9234069
let's try to map some of our params to the params mentioned in this link,
For ex: page_view ==>

Copy link
Contributor

Choose a reason for hiding this comment

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

Also check if GA4 allows sending campaign info present under rudderElement.message.context.campaign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added function to support GA4 params and added config to decide if need to send extra params

identify(rudderElement) {
if (this.sendUserId && rudderElement.message.userId) {
const userId = this.analytics.userId || this.analytics.anonymousId;
window.gtag("config", this.measurementId, {
Copy link
Contributor

Choose a reason for hiding this comment

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

this works even if identify is not the first call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, user is identified even if no identify call is made. As soon as ga scripts load he gets identified in google analytics.

throw Error("Cannot call un-named/reserved named track event");
}

const obj = this.getDestinationEvent(event);
Copy link
Contributor

Choose a reason for hiding this comment

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

better name like destEventName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/* utility functions --- Ends here --- */

isReservedName(eventName) {
const reservedName = [
Copy link
Contributor

Choose a reason for hiding this comment

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

reservedEventNames

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,83 @@
const eventName = [
Copy link
Contributor

Choose a reason for hiding this comment

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

eventNamesConfigArray

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// --------
];

const eventParameter = [
Copy link
Contributor

Choose a reason for hiding this comment

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

similar as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

{ src: "checkout_id", dest: ["transaction_id"] },
];

const itemParameter = [
Copy link
Contributor

Choose a reason for hiding this comment

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

similar as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sayan-mitra
Copy link
Contributor

sayan-mitra commented Dec 18, 2020

use prettier and eslint in vs code. It will take the config from .prettierrc and .eslintrc present in the repo.
This will help resolve the new files as much as possible.
Can you try that @Shivam4415

@@ -17,8 +17,12 @@ import * as Optimizely from "./Optimizely";
import * as Bugsnag from "./Bugsnag";
import * as Fullstory from "./Fullstory";
import * as TVSquared from "./TVSquared";
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

missed this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it

}

page(rudderElement) {
const page =
Copy link
Contributor

Choose a reason for hiding this comment

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

change to pageProps
get the value from message.properties. Reason: for page call to Rudder SDK ==> this is the syntax:
page(, {}, ...)
here properties can be any custom param, which is not present un message.context.page (the contextual info only contains standard params like referrer, url, title etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

);
}

function getDestinationEventProperties(props, destParameter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

destParameter ==> destParameterConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return reservedEventNames.includes(name);
}

function getDestinationEventName(events) {
Copy link
Contributor

Choose a reason for hiding this comment

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

events ==> event

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
/* utility functions --- Ends here --- */

getDestinationItemProperties(products, item) {
Copy link
Contributor

Choose a reason for hiding this comment

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

forgot to remove from here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now removed

const items = [];
let obj = {};
products.forEach((p) => {
obj = {
Copy link
Contributor

Choose a reason for hiding this comment

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

better name than obj

Copy link
Contributor Author

Choose a reason for hiding this comment

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

obj -> eventMappingObj

{ src: "affiliation", dest: ["affiliation"] },
{ src: "shipping", dest: ["shipping"] },
{ src: "tax", dest: ["tax"] },
{ src: "affiliation", dest: ["affiliation"] },
Copy link
Contributor

Choose a reason for hiding this comment

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

remove duplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sayan-mitra
Copy link
Contributor

add a way to check and abort if item_id/item_name, promotion_id/promotion_name, search_term are not present in the final destination payload.
ref: https://developers.google.com/gtagjs/reference/ga4-events#view_promotion

@sayan-mitra
Copy link
Contributor

  1. Update getDestinationEventProperties logic as discussed
  2. formatting fixes
  3. method definition examples and comments
  4. Wishlist and share(product and cart) mapping
  5. Utility to Utils
  6. Move tests under GA folder to keep it localised and keep on completing it


const eventParametersConfigArray = [
{ src: "query", dest: ["search_term"] },
{ src: "list_id", dest: ["item_list_id", "items.item_list_id"] },
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of array, use a flag like storeAlsoInItems: true/false
that will make the parsing simpler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okkk looking into it

],
hasItem: true,
hasMultiplePayload: true,
Copy link
Contributor

@sayan-mitra sayan-mitra Dec 21, 2020

Choose a reason for hiding this comment

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

do we need this?
can we do this:
{
src: ["payment info entered"],
dest: "add_payment_info",
hasItem: false,
onlyIncludeParams: includeParams.PaymentInfo,
},

{
src: ["payment info entered"],
dest: "add_shipping_info",
hasItem: false,
onlyIncludeParams: includeParams.ShippingInfo,
},

and filter multiple events by same src name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can do this as well

Shivam4415 and others added 3 commits December 21, 2020 18:30
…dMultiplepayload flag. Also includeList instead of onlyparams for Payment Info Entered.
@sayan-mitra sayan-mitra changed the base branch from production to production-staging December 21, 2020 16:14
@sayan-mitra sayan-mitra merged commit b84af1b into production-staging Dec 21, 2020
@akashrpo akashrpo deleted the ga4/prod branch March 5, 2022 10:28
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.

2 participants