Closed GeorgeTaveras1231 closed 5 years ago
Hi @GeorgeTaveras1231, thanks for reaching out - for Google Tag Manager we actually recommend a slightly different loading snippet which does not stub out the SDK's interface and therefore does not include that long string - you can see that snippet here: https://github.com/appboy/appboy-web-sdk#alternative-google-tag-manager-installation - we recommend using that snippet because it should also prevent potential issues in GTM with the way appboyQueue
is referenced in the snippet you pasted above. For GTM, these additional elements are simply unnecessary complication, as long as you fire the recommended loading snippet on page load as described at the link I provided. Let me know if that solves your issue. :)
Hey @froodian. We actually took a look at the alternative GTM installation but we were concerned about the fact that it did not include the stubbed API; we felt that this could compound race conditions if a developer needed to use any of the appboy
methods, because their code would have to run only after the sdk is loaded. However, I can see how there is still a potential for race conditions by just using GTM, because (even with the stubbed API) you would need to wait for GTM to load the tag that defines the stub. I still feel like there is value in having the stubbed API, but if you guys feel strongly about using the alternative snippet than we can look into doing that instead.
Hi @GeorgeTaveras1231 - you make a fair point. I have an update prepared locally that I think should allow the interface stubbing snippet to work in GTM. It will definitely require us to push out a minor SDK release in for it to function properly (to work around the additional issues that I obliquely alluded to which exist today with appboyQueue
and the current SDK assuming internally that the variable scope is window
, which is untrue in GTM).
Before we do that release, I just want to confirm with you that the following draft snippet causes the error you saw to go away:
+function(a,p,P,b,y){a.appboy={};a.appboyQueue=[];
for(var s="initialize destroy getDeviceId toggleAppboyLogging setLogger openSession changeUser requestImmediateDataFlush requestFeedRefresh subscribeToFeedUpdates requestContentCardsRefresh subscribeToContentCardsUpdates logCardImpressions logCardClick logCardDismissal logFeedDisplayed logContentCardsDisplayed logInAppMessageImpression logInAppMessageClick logInAppMessageButtonClick logInAppMessageHtmlClick subscribeToNewInAppMessages removeSubscription removeAllSubscriptions logCustomEvent logPurchase isPushSupported isPushBlocked isPushGranted isPushPermissionGranted registerAppboyPushMessages unregisterAppboyPushMessages submitFeedback trackLocation stopWebTracking resumeWebTracking wipeData ab ab.DeviceProperties ab.User ab.User.Genders ab.User.NotificationSubscriptionTypes ab.User.prototype.getUserId ab.User.prototype.setFirstName ab.User.prototype.setLastName ab.User.prototype.setEmail ab.User.prototype.setGender ab.User.prototype.setDateOfBirth ab.User.prototype.setCountry ab.User.prototype.setHomeCity ab.User.prototype.setLanguage ab.User.prototype.setEmailNotificationSubscriptionType ab.User.prototype.setPushNotificationSubscriptionType ab.User.prototype.setPhoneNumber ab.User.prototype.setAvatarImageUrl ab.User.prototype.setLastKnownLocation ab.User.prototype.setUserAttribute ab.User.prototype.setCustomUserAttribute ab.User.prototype.addToCustomAttributeArray ab.User.prototype.removeFromCustomAttributeArray ab.User.prototype.incrementCustomUserAttribute ab.User.prototype.addAlias ab.User.prototype.setCustomLocationAttribute ab.InAppMessage ab.InAppMessage.SlideFrom ab.InAppMessage.ClickAction ab.InAppMessage.DismissType ab.InAppMessage.OpenTarget ab.InAppMessage.ImageStyle ab.InAppMessage.TextAlignment ab.InAppMessage.Orientation ab.InAppMessage.CropType ab.InAppMessage.prototype.subscribeToClickedEvent ab.InAppMessage.prototype.subscribeToDismissedEvent ab.InAppMessage.prototype.removeSubscription ab.InAppMessage.prototype.removeAllSubscriptions ab.InAppMessage.prototype.closeMessage ab.InAppMessage.Button ab.InAppMessage.Button.prototype.subscribeToClickedEvent ab.InAppMessage.Button.prototype.removeSubscription ab.InAppMessage.Button.prototype.removeAllSubscriptions ab.SlideUpMessage ab.ModalMessage ab.FullScreenMessage ab.HtmlMessage ab.ControlMessage ab.Feed ab.Feed.prototype.getUnreadCardCount ab.ContentCards ab.ContentCards.prototype.getUnviewedCardCount ab.Card ab.ClassicCard ab.CaptionedImage ab.Banner ab.ControlCard ab.WindowUtils display display.automaticallyShowNewInAppMessages display.showInAppMessage display.showFeed display.destroyFeed display.toggleFeed display.showContentCards display.hideContentCards display.toggleContentCards sharedLib".split(" "),i=
0;i<s.length;i++){for(var m=s[i],k=a.appboy,l=m.split("."),j=0;j<l.length-1;j++)k=k[l[j]];k[l[j]]=(new Function("return function "+m.replace(/\./g,"_")+"(){window.appboyQueue.push(arguments); return true}"))()}window.appboy.getUser=function(){return new window.appboy.ab.User};window.appboy.getCachedFeed=function(){return new window.appboy.ab.Feed};window.appboy.getCachedContentCards=function(){return new window.appboy.ab.ContentCards};
(y=p.createElement(P)).type='text/javascript';
y.src='https://js.appboycdn.com/web-sdk-develop/2.3/appboy.min.js';
y.async=1;(b=p.getElementsByTagName(P)[0]).parentNode.insertBefore(y,b)
}(window,document,'script');
(this snippet still uses the long string - it requires fewer characters than defining each string separately in an array - but from the error message about "contiguous non-whitespace characters", I think GTM was actually complaining about a slightly different portion of the original snippet)
Note that until we do that Web SDK release, this draft snippet will not function properly (enqueued methods will not be replayed when the SDK loads) but you should hopefully see that particular error go away. Can you confirm that? Assuming that's correct, we should be able to push out the SDK update shortly.
@froodian I tried to use the snippet you gave and am still getting the validation error in GTM. For what its worth, I had previously tried manually updating the default JS snippet to no longer use a string/split implementation but instead use a fixed array implementation with spaces between each entry ( ["initialize", "destroy", ....
) on our QA environment and that was accepted by GTM.
I see, thanks for the update, I guess an array it is then. We'll get that update out as soon as possible.
Thanks @froodian. If there is another snippet you'd like us to try out on our side before you perform any release let me know and I'm happy to test in GTM.
Sorry, I didn't mean to close this issue yet - I merged a pull internally that said it fixes this, but it is not yet released - stay tuned, I should have that release ready in the next day or two. I was able to test the validation in GTM myself, but thank you for that offer.
We've now released Web SDK 2.3.2 which should work correctly in GTM when used with this snippet: https://github.com/appboy/appboy-web-sdk#alternative-google-tag-manager-installation - just let me know if you have any other issues in this area or if this doesn't function as expect - barring any problems there, I'm closing this issue as fixed. :)
My team is working on integrating braze through our site using GTM and recently ran into an issue with the default install snippet:
The error is:
After digging, we found that the source of the problem is in this line of code:
It seems like that string used to generate the API shell, is too big, and GTM has some constraints on the size of raw strings.
Is it possible to change that line of code to use an array of strings instead of a large string?
That seems like a fairly simple change, especially since the string is
split
anyways before it is passed to other parts of the code.