-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: exceptional max attribute length and page_referrer flag addition #59
fix: exceptional max attribute length and page_referrer flag addition #59
Conversation
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.
Looks good so far. Most of my feedback is related to questions and some readability suggestions.
packages/GA4Client/src/common.js
Outdated
var val; | ||
switch (key) { | ||
case 'page_title': | ||
val = truncateString( | ||
attributes[attribute], | ||
PAGE_TITLE_MAX_LENGTH | ||
); | ||
break; | ||
case 'page_referrer': | ||
val = truncateString( | ||
attributes[attribute], | ||
PAGE_REFERRER_MAX_LENGTH | ||
); | ||
break; | ||
case 'page_location': | ||
val = truncateString( | ||
attributes[attribute], | ||
PAGE_LOCATION_MAX_LENGTH | ||
); | ||
break; | ||
default: | ||
val = truncateString(attributes[attribute], valueLimit); | ||
} |
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.
From a readability standpoint, I think it makes things more clear that you're overriding the value limit by just changing valueLimit
inside of the switch chase.
Then it becomes:
var val; | |
switch (key) { | |
case 'page_title': | |
val = truncateString( | |
attributes[attribute], | |
PAGE_TITLE_MAX_LENGTH | |
); | |
break; | |
case 'page_referrer': | |
val = truncateString( | |
attributes[attribute], | |
PAGE_REFERRER_MAX_LENGTH | |
); | |
break; | |
case 'page_location': | |
val = truncateString( | |
attributes[attribute], | |
PAGE_LOCATION_MAX_LENGTH | |
); | |
break; | |
default: | |
val = truncateString(attributes[attribute], valueLimit); | |
} | |
var valueLimitOverride; | |
switch (key) { | |
case 'page_title': | |
valueLimitOverride = PAGE_TITLE_MAX_LENGTH; | |
break; | |
case 'page_referrer': | |
valueLimitOverride = PAGE_REFERRER_MAX_LENGTH | |
break; | |
case 'page_location': | |
valueLimitOverride = PAGE_LOCATION_MAX_LENGTH | |
break; | |
default: | |
valueLimitOverride = valueLimit; | |
} | |
var val = truncateString(attributes[attribute], valueLimitOverride); |
pageTitle = document.title, | ||
pageReferrer = document.referrer; |
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.
pageTitle = document.title, | |
pageReferrer = document.referrer; | |
var pageTitle = document.title; | |
var pageReferrer = document.referrer; |
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.
if this is accepted as a suggestion, update the ,
on line 78 to a ;
as well
@@ -1522,6 +1522,7 @@ describe('Google Analytics 4 Event', function () { | |||
{ | |||
page_title: 'Mocha Tests', | |||
page_location: location.href, | |||
page_referrer: document.referrer, |
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.
I see that you added some tests that include page_referrer
but are there any tests cases that reflect the behavior when it isn't included?
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.
so as mentioned the default for page_referrer per google docs is document.referrer and I included it just how we default page_title and page_location
packages/GA4Client/src/common.js
Outdated
var val = truncateString(attributes[attribute], valueLimit); | ||
var val; | ||
switch (key) { | ||
case 'page_title': |
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.
I would make each case a variable at the top of the page below the variables for max lengths
pageTitle = document.title, | ||
pageReferrer = document.referrer; |
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.
if this is accepted as a suggestion, update the ,
on line 78 to a ;
as well
packages/GA4Client/test/src/tests.js
Outdated
@@ -1644,6 +1647,7 @@ describe('Google Analytics 4 Event', function () { | |||
{ | |||
page_title: 'Foo Page Title', | |||
page_location: '/foo', | |||
page_referrer: document.referrer, |
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.
any reason this is a reference to document.referrer
an dnot a string like the others?
also changed the branch we are pr-ing into from |
I had to do some syncing of |
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.
LGTM - once @alexs-mparticle has another look, we can merge
## [1.4.3](v1.4.2...v1.4.3) (2024-05-07) ### Bug Fixes * exceptional max attribute length and page_referrer flag addition ([#59](#59)) ([d81fff3](d81fff3))
Summary
This PR covers a bug fix and a feature request:
GA4.Referrer
for the mapping. This flag has no legacy backwards compatibility as it wasn't available for GA Universal as you can see in the screenshot below taken from this GA support doc hereAlso, just like the flags GA4.Location (page_location) and GA4.Title (page_title) I did include it's default value in case it was not provided by the customer which in this case is the
document.referrer
as mentioned here in this google support docTesting Plan
Master Issue
Closes https://mparticle-eng.atlassian.net/browse/PRODRDMP-6731 and https://mparticle.lightning.force.com/lightning/r/Gap_Opportunity_Connector__c/a0uRg000001RWHlIAO/view