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

Allow for usage of snowplow callback without this #1407

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

greg-el
Copy link
Contributor

@greg-el greg-el commented Jan 22, 2025

This PR allows for the snowplow(function() {}) callback to get tracker information without requiring the this keyword, which is useful in environments that don't support the keyword (GTM) and is a non-breaking change.

The callback has been updated to pass the tracker dictionary (the object that is referred to by this) as the last argument. This allows for it to be used as a simple replacement for this, like so:

snowplow(function (trackers) {
    var sp = trackers.sp;
    var domainUserId = sp.getDomainUserId();
});

As it is the last parameter, it still allows for the passing of arguments in the snowplow function:

snowplow(function(a, b, trackers) {
    console.log(a, b); // 1, 2
    var sp = trackers.sp;
    var domainUserId = sp.getDomainUserId();
}, 1, 2);

The this keyword is still supported in conjunction with the parameter:

snowplow(function(trackers) {
  trackers.sp.getDomainUserId() === this.sp.getDomainUserId() // true
});

@greg-el greg-el changed the base branch from master to release/4.3.2 January 22, 2025 16:25
@greg-el greg-el force-pushed the issue/1085-snowplow-callback-without-this branch from 9dfdec6 to 67cb901 Compare January 22, 2025 16:59
Copy link

bundlemon bot commented Jan 22, 2025

BundleMon

Files added (6)
Status Path Size Limits
trackers/javascript-tracker/dist/sp.js
+24.56KB 30KB / +10%
libraries/browser-tracker-core/dist/index.mod
ule.js
+23.59KB 25KB / +10%
libraries/tracker-core/dist/index.module.js
+19.5KB 20KB / +10%
trackers/browser-tracker/dist/index.umd.min.j
s
+17.44KB 20KB / +10%
trackers/javascript-tracker/dist/sp.lite.js
+17.41KB 20KB / +10%
trackers/browser-tracker/dist/index.module.js
+3.49KB 5KB / +10%

Total files change +105.99KB 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history

@greg-el greg-el marked this pull request as ready for review January 22, 2025 18:07
Copy link
Contributor

@jethron jethron left a comment

Choose a reason for hiding this comment

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

LGTM if LGT @matus-tomlein

Copy link
Contributor

@matus-tomlein matus-tomlein left a comment

Choose a reason for hiding this comment

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

LGTM!

@greg-el greg-el changed the base branch from release/4.3.2 to release/4.4.0 January 23, 2025 13:44
@greg-el greg-el force-pushed the issue/1085-snowplow-callback-without-this branch from 7e3f9af to 598b2fa Compare January 23, 2025 14:55
@greg-el greg-el force-pushed the issue/1085-snowplow-callback-without-this branch from 598b2fa to 672a374 Compare January 23, 2025 15:01
@greg-el greg-el merged commit 6f87b5a into release/4.4.0 Jan 23, 2025
2 checks passed
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