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

fix: exceptional max attribute length and page_referrer flag addition #59

Conversation

mmustafa-tse
Copy link
Contributor

@mmustafa-tse mmustafa-tse commented Apr 30, 2024

Summary

This PR covers a bug fix and a feature request:

  • fix: Google has a couple of exceptions for some attributes/params max lengths such as page_title (300 chars), page_location (1000 chars), page_referrer (420 chars) (doc here) while we automatically truncate every attribute and custom flag to 100 chars, this resulted in an issue where the customer reported missing attribution on the Google Ads side due to this issue.
  • feature request: GA4 has a special param page_referrer that is similar to page_title and page_location and the request here is to include it as a custom flag to map into it. I included the new flag 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 here
Screenshot 2024-04-30 at 9 50 08 AM

Also, 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 doc

Testing Plan

  • Included new and modified some unit tests and it passed as expected.
  • tested E2E using local overrides with the new code implemented and it worked as expected

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

Copy link
Contributor

@alexs-mparticle alexs-mparticle left a 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.

Comment on lines 73 to 95
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);
}
Copy link
Contributor

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:

Suggested change
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);

Comment on lines 79 to 80
pageTitle = document.title,
pageReferrer = document.referrer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pageTitle = document.title,
pageReferrer = document.referrer;
var pageTitle = document.title;
var pageReferrer = document.referrer;

Copy link
Collaborator

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/src/event-handler.js Show resolved Hide resolved
@@ -1522,6 +1522,7 @@ describe('Google Analytics 4 Event', function () {
{
page_title: 'Mocha Tests',
page_location: location.href,
page_referrer: document.referrer,
Copy link
Contributor

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?

Copy link
Contributor Author

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

var val = truncateString(attributes[attribute], valueLimit);
var val;
switch (key) {
case 'page_title':
Copy link
Collaborator

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

Comment on lines 79 to 80
pageTitle = document.title,
pageReferrer = document.referrer;
Copy link
Collaborator

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/src/event-handler.js Show resolved Hide resolved
@@ -1644,6 +1647,7 @@ describe('Google Analytics 4 Event', function () {
{
page_title: 'Foo Page Title',
page_location: '/foo',
page_referrer: document.referrer,
Copy link
Collaborator

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?

@rmi22186 rmi22186 changed the base branch from master to development May 2, 2024 01:02
@rmi22186
Copy link
Collaborator

rmi22186 commented May 2, 2024

also changed the branch we are pr-ing into from master to development

@rmi22186 rmi22186 changed the base branch from development to master May 3, 2024 16:34
@rmi22186 rmi22186 changed the base branch from master to development May 3, 2024 16:34
@rmi22186
Copy link
Collaborator

rmi22186 commented May 3, 2024

I had to do some syncing of master and development, and had to update the branch for some reason to remove some commits that were in development already.

Copy link
Collaborator

@rmi22186 rmi22186 left a 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

@rmi22186 rmi22186 merged commit d81fff3 into mparticle-integrations:development May 3, 2024
4 checks passed
github-actions bot pushed a commit that referenced this pull request May 7, 2024
## [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))
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