klaviyo / magento2-klaviyo

37 stars 51 forks source link

Use Magento URL builder to build URLs #137

Closed njparadis closed 2 years ago

njparadis commented 2 years ago

Implements change suggested in #94 and also implements this URL builder on cart.phtml template

Also replaces reference to deprecated _learnq functionality (_learnq.identify.$email) with an equivalent (_learnq.isIdentified())

jordanallain commented 2 years ago

assuming this was tested, lgtm! tiny nit, you could alphabetize the library names that are being required.

ihor-sviziev commented 2 years ago

@njparadis, Could you provide a bit more info about the _learnq.identify.$email to _learnq.isIdentified() change? How long the old version will work? Is there any other related changes to it? I'm asking it because I didn't see any related info in the klaviyo docs, and we also using this functionality in our own modules.

njparadis commented 2 years ago

@njparadis, Could you provide a bit more info about the _learnq.identify.$email to _learnq.isIdentified() change? How long the old version will work? Is there any other related changes to it? I'm asking it because I didn't see any related info in the klaviyo docs, and we also using this functionality in our own modules.

On June 16, 2021, Klaviyo changed how we generate our email-to-web tracking token and deprecated the old token that same day at 3pm Eastern. Going forward we are using an encrypted token in all email-to-web tracking.

This update to the token removed the $email and the $phone_number properties from _learnq.identify as this information is no longer accessible client-side.

After the June 16 change, Klaviyo recommends updating onsite code to use the preferred _learnq.isIdentified() call. This function will indicate if an on-site user is recognized by Klaviyo with a simple true/false response.

One other side effect of this change is that there can be a race condition between calls to identify() and track() in some situations. For example, when an unknown user fills out a custom signup form, you pass the email address from the form to identify() and then immediately try to record an event for that user with a call to track(). If the HTTP request to retrieve the encrypted token hasn't resolved when track() fires, the event will not be recorded.

To prevent this, identify() allows for a callback function to be passed as the 4th positional argument, eg:

function onIdentifyCompleteCallback () {
    _learnq.track("Neat Event");
}

_learnq.identify(identityProperties, undefined, undefined, onIdentifyCompleteCallback)