Enabling Google AdWords Causes Error on Login
In some implementations of Vinson, Google Ads (previously called Google Adwords) can cause the following error:
"Uncaught TypeError: e.doCallback is not a function"
This error can occur when the following conditions are met:
-
Google Ads is enabled for a domain.
-
A customer adds items to their cart and logs out without completing the transaction.
-
The customer then attempts to log in again.
This error occurs in the Tracker module. To fix the error, you must extend the prototype
object of the Tracker.prototype.trackEvent()
function. For an example of the changes needed for this patch, see EnablingGoogleAdWordsCausesErroronLogin.zip.
Before proceeding, familiarize yourself with Best Practices for Customizing SCA.
Step 1: Extend the Tracker.js File
-
If you have not done so already, create a directory to store your custom module.
Give this directory a name similar to the module being customized. For example, create
Modules/extensions/TrackerExtension@1.0.0
-
In your new TrackerExtension @1.0.0 directory, create a subdirectory called
JavaScript
.For example:
Modules/extensions/TrackerExtension@1.0.0/JavaScript
-
In your new JavaScript subdirectory, create a JavaScript file to extend Tracker.js.
Name this file according to best practices. For example:
TrackerExtension.js
-
Open this file and extend the
Tracker.prototype.trackEvent()
method as shown in the following code snippet.//@module Tracker define('TrackerExtension' , [ 'Tracker', 'underscore' ] , function ( Tracker, _ ) { 'use strict'; _.(extend Tracker.prototype, Tracker.prototype.trackEvent = function Tracker.prototype.trackEvent (event) { this.track('trackEvent', event); if (event.callback) { var doCallback = _.find(this.trackers, function (tracker) { return tracker.doCallback && tracker.doCallback(); }); !doCallback && event.callback(); } return this; }; } });
-
Save the file.
Step 2: Prepare the Developer Tools For Your Customization
-
Open your new TrackerExtension@1.0.0 module directory.
-
Create a file in this directory and name it ns.package.json.
Modules/extensions/TrackerExtension@1.0.0/ns.package.json
-
Build the ns.package.json file using the following code:
{ "gulp": { "javascript": [ "JavaScript/*.js" ] } }
-
Open the distro.json file. This is located in your root directory.
-
Add your custom modules to the
modules
object.Your code should look similar to the following example:
{ "name": "SuiteCommerce Advanced Vinson Release", "version": "2.0", "buildToolsVersion": "1.2.1", "folders": { "modules": "Modules", "suitecommerceModules": "Modules/suitecommerce", "thirdPartyModules": "Modules/third_parties", "distribution": "LocalDistribution", "deploy": "DeployDistribution" }, "modules": { "extensions/TrackerExtension": "1.0.0", "suitecommerce/Account": "2.2.0", ...
This ensures that the Gulp tasks include your module when you deploy. In this example, the custom modules are added at the beginning of the list of modules. However, you can add the modules anywhere in the
modules
object. The order of precedence in this list does not matter. -
Add
TrackerExtension
as a dependency to SCA entry point within theSC.Shopping.Starter
entrypoint of the JavaScript array.Your distro.js file should look similar to the following:
"tasksConfig": { // ... "javascript": [ // ... { "entryPoint": "SC.Shopping.Starter", "exportFile": "shopping.js", "dependencies": [ // ... "TrackerExtension", "Backbone.View.Plugins", "jQuery.html", // ...
-
Save the distro.json file.
Step 3: Test and Deploy Your Customization
-
Test your source code customizations on a local server (see Test SCA Customizations on a Local Server) or deploy them to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.
-
Confirm your results.
Upon successful deployment, enabling Google Ads does not cause errors when a customer logs in or out with items in the cart.