Set Up Google Tag Manager

This topic applies to SuiteCommerce and the 2018.2 release of SuiteCommerce Advanced (SCA) and later. If you are implementing SCA Aconcagua or earlier, see Set Up Google Tag Manager (SuiteCommerce Advanced Aconcagua and Earlier) for instructions.

Note:

For implementations of SCA 2018.2 – 2022.2 using Google Analytics 4 with the Google Tag Manager Commerce Extension, review the data-layer structure of SCA version 2023.1 or later and compare it with your current version. With the release of SCA 2023.1, modifications were made in the data-layer code to comply with Google and correctly track information with Google Analytics events. For information about the suggested data-layer structure you should use, see Google Tag Manager Events Not Displaying in Data Layer Upon Checkout.

Google Tag Manager (GTM) set up involves several steps in NetSuite and in Google applications. To set up GTM for your Commerce website, complete the steps shown in the following figure.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Install SC Google Tag Manager Editor

Install the SC Google Tag Manager Editor SuiteApp to use Google Tag Manager Editor. See Installing Theme and Extension SuiteApps for instructions about how to install an extension SuiteApp. See Commerce Extensions for the SC Google Tag Manager Editor bundle ID.

Sign Up for Google Tag Manager

To sign up for a GTM account, you must first have a Google account. If you don’t already have a Google account, create one following Google's instructions. See Create your Google Account.

When you sign up for your GTM account, Google creates your GTM account and a container to hold your tags, macros, and rules.

To sign up for a Google Tag Manager account:

  1. Go to https://www.google.com/analytics/tag-manager/.

  2. Sign in to GTM with your Google ID.

  3. Click Create Account.

  4. Enter a name for your account.

  5. Select your country from the Country field.

  6. Click Continue.

  7. Enter your site name in the Container Name field.

    Example: www.mysite.com

  8. Select Web from the Where to Use Container field.

  9. Click Create.

  10. Close the Install Google Tag Manager window.

    Note:

    You do not need the GTM code displayed in this window.

  11. Go to the GTM Workspace tab and make a note of the GTM ID located in the submenu header area in the upper right portion of the page.

    GTM workspace, GTM ID.

Enable the Google Tag Manager API

You must enable the GTM API prior to authenticating your NetSuite Account with the Google API.

  1. Log in to Google API Credentials Console using your Google account logins.

  2. Enter Google Tag Manager in the search box and select API Tag Manager from the search results.

  3. Click Enable.

Authenticate Your NetSuite Account with the Google API

Google requires you to authenticate your NetSuite account with the Google API using a Google OAuth Client ID. Complete the following procedures to create a free Google OAuth Client ID and authenticate your NetSuite account with the Google API:

  1. Create your Google API OAuth Client ID credentials.

  2. Provide values for your Google API OAuth consent screen.

  3. Link your Google API OAuth client ID to your NetSuite account.

Note:

You only need to perform these steps one time in your NetSuite account.

To create your Google API OAuth client ID credentials:

  1. Log in to the Google API Credentials Console using your Google account logins.

  2. Click Create credentials > OAuth client ID.

  3. On the credentials form, select Web application for the application type.

  4. Enter NetSuite in the Name field.

  5. Enter your Authorized JavaScript origins and Authorized redirect URIs (Uniform Resource Identifiers).

    Important:

    Log in to your NetSuite account and make a note of your NetSuite account URL. Enter this URL (beginning with https and ending with netsuite.com) in the Authorized JavaScript origins and Authorized redirect URIs fields. Example: https://3925220.app.netsuite.com.

    Enter the values shown in the following table.

    Field Name

    Value

    Authorized JavaScript origins

    <Your NetSuite account URL>

    https://system.netsuite.com

    https://system.na1.netsuite.com

    https://system.na2.netsuite.com

    https://system.na3.netsuite.com

    https://system.eu1.netsuite.com

    https://system.eu2.netsuite.com

    https://system.eu3.netsuite.com

    Authorized redirect URIs

    <Your NetSuite account URL>

    https://system.netsuite.com

    https://system.na1.netsuite.com

    https://system.na2.netsuite.com

    https://system.na3.netsuite.com

    https://system.eu1.netsuite.com

    https://system.eu2.netsuite.com

    https://system.eu3.netsuite.com

  6. Click Create. A modal window provides your OAuth client ID and client secret.

  7. Make a note of your OAuth client ID value and click OK.

Note:

The Google API consent screen tells your users who is requesting access to their data and what kind of data you’re asking to access.

To provide values for your Google API OAuth consent screen:

  1. Log in to Google API Credentials Console using your Google account logins.

  2. Click Credentials in the left navigation bar.

  3. Click the OAuth consent screen tab.

  4. Enter the values shown in the following table.

    Field Name

    Value

    Details

    Application name

    NetSuite

    -

    Application Logo

    -

    Upload your company logo (optional).

    Support email

    <valid email address>

    Enter the email address of the person at your company responsible for answering data security questions.

    Authorized domains

    netsuite.com

    -

    Application Homepage link

    https://www.netsuite.com/

    -

    Application Privacy Policy link

    http://www.netsuite.com/portal/privacy.shtml

    -

    Applications Terms of Service link

    <URL for your terms of service>

    Enter the URL of your terms of service page (optional).

  5. Click Save.

  6. Click the Edit OAuth client icon (pencil).

  7. Enter the values in the following table if they do not already exist:

    Important:

    Log in to your NetSuite account and make a note of your NetSuite account URL. Enter this URL (beginning with https and ending with netsuite.com) in the Authorized JavaScript origins and Authorized redirect URIs fields. Example: https://3925220.app.netsuite.com.

    Field Name

    Value

    Name

    NetSuite

    Authorized JavaScript origins

    <Your NetSuite account URL>

    https://system.netsuite.com

    https://system.na1.netsuite.com

    https://system.na2.netsuite.com

    https://system.na3.netsuite.com

    https://system.eu1.netsuite.com

    https://system.eu2.netsuite.com

    https://system.eu3.netsuite.com

    Authorized redirect URIs

    <Your NetSuite account URL>

    https://system.netsuite.com

    https://system.na1.netsuite.com

    https://system.na2.netsuite.com

    https://system.na3.netsuite.com

    https://system.eu1.netsuite.com

    https://system.eu2.netsuite.com

    https://system.eu3.netsuite.com

  8. Click Save.

To link your Google API OAuth client ID to your NetSuite account:

  1. In NetSuite, go to Setup > Company > General Preferences.

  2. Go to the Custom Preferences tab.

  3. Enter or paste your OAuth Client ID in the Google OAuth Client ID field.

  4. Click Save.

Link your Google Tag Manager Account to a Domain

Link your GTM ID to the SuiteCommerce configuration record for the associated domain.

To link your Google Tag Manager account to your domain:

  1. Go to Commerce > Web Sites > Configuration.

  2. Select your website and domain and click Configure.

  3. In the configuration record, go to the Integrations tab and the Google Tag Manager subtab.

  4. Enter your GTM ID in the Google Tag Manager ID field.

    Leave the Google Tag Manager Data Name field set to the default value of dataLayer.

    For more information, see Google Tag Manager Subtab.

  5. If you use separate domains for shopping and checkout, check the Is A Multi-Domain Site box.

  6. Click Save.

Add Services to Your Google Tag Manager Container

Add supported service to your GTM container using the steps provided below. You can add additional services without leaving GTM Editor, but you must add each one separately. GTM Editor creates the tags, triggers, and variables needed for the selected service and adds them to your GTM container. See Supported Google Tag Manager Services for a list of all supported services.

To add services to your Google Tag Manager container:

  1. In NetSuite, go to Setup > SuiteCommerce Advanced > Google Tag Manager Editor.

  2. Click Sign In With Google and choose your account.

  3. Authorize NetSuite to access your Google account by clicking Allow for each permission.

  4. On the Accounts & Containers – Google Tag Manager Editor page, click your container name.

  5. Click Add Service.

  6. Select the service you want to add in the Service menu.

  7. Fill in the fields for the service you are adding.

    Each service has a different set of fields that apply to that service. For example, if you are adding the Google Analytics service, you must enter a unique name of your choice, your Google Analytics tracking ID, and the domains you want to use with this service. Click the question mark icon for more information about finding the values to enter in these fields.

  8. Click Add. If one instance of the service already exists, a warning displays with a link to edit the existing service. If more than one instance of the service already exists, a warning displays with a link to the list of existing container services.

You can now go to your GTM account (tagmanager.google.com) and your container, and see all of the tags, triggers, and variables added to your container.

Review and Publish Your Changes

After you add a new service to your container, the changes are displayed in GTM, but not yet published on your website.

To review and publish your changes:

  1. From the Container Services page in the GTM, click Review and Publish Changes.

    This redirects you to your workspace and container in GTM.

  2. On the GTM Workspace page, click Submit.

  3. On the Submit Changes page, you can add a version name and description.

    Adding this information is optional, but adding it makes it easier for you to identify the changes made to your container.

  4. Click Publish.

To view the data produced by each tag, log in to the service provider’s page. For example, to view data produced by the Google Analytics tag, log in to your Google Analytics account and view the results on the Google Analytics site (analytics.google.com).

Preserve Google Tag Manager Session Data

Complete the following procedures to preserve the data from shopping and checkout sessions. The scheduling script and associated scheduler (JavaScript) file deletes the session data when it is no longer needed.

  1. Enable SuiteScript and Custom Records — This procedure provides instructions for enabling SuiteScript and custom records in NetSuite.

  2. Create a Custom Record — This procedure provides instructions for creating custom records used to store data between sessions.

  3. Create Scheduler File — This procedure provides instructions for creating the scheduler file that deletes unneeded session data records every 60 minutes.

  4. Create Scheduler Script — This procedure provides instructions for creating the scheduler script that runs every 60 minutes.

To enable SuiteScript and Custom Records:

  1. In NetSuite, go to Setup > Company > Enable Features.

  2. Go to the SuiteCloud tab. In the SuiteBuilder section, check the Custom Records box.

  3. In the SuiteScript section, check the following boxes:

    • Client SuiteScript

    • Server SuiteScript

    • SuiteScript Server Pages

  4. Click Save.

To create a custom record:

  1. In NetSuite, go to Customization > Lists, Records & Fields > Record Types > New.

  2. In the Name field, enter a name for your custom record.

    Example: SC GTM DataLayer

  3. In the ID field, enter: _ns_gtm_datalayer.

    Enter this value exactly as shown (including the underscore character at the front).

  4. In the Access Type list, select No Permission Required.

  5. Clear the Include Name Field box.

  6. Click Save.

  7. The new Custom Record Type page displays. The title of your new record type is displayed in the Name field.

  8. Go to the Fields tab and add two new fields: gtm_id and gtm_events. Use the settings and values shown in the following table.

    For information about how to add fields to a custom record type, see Adding Fields to Custom Record Types.

    Field

    Field List 1 (gtm_id)

    Field List 2 (gtm_events)

    Label/Description

    gtm_gid

    gtm_events

    ID

    _ns_gtm_gid

    _ns_gtm_events

    Owner

    Autopopulates with Your Name

    Autopopulates with Your Name

    Description

    Enter a description of your choice (optional)

    Enter a description of your choice (optional)

    Type

    Free-Form Text

    Long Text

    List/Record

    -

    -

    Store Value

    Enable

    Enbale

    Use Encrypted Format

    Disable

    Disable

    Show in List

    Disable

    Disable

    Global Search

    Disable

    Disable

    Record is Parent

    -

    -

    Inactive

    Disable

    Disable

    Apply Role Restrictions

    -

    -

    Access Tab: Default Access Level

    Edit

    Edit

    Access Tab: Default Level For Search/Reporting

    Edit

    Edit

  9. Save the file in any accessible location.

To create the scheduler file:

  1. Using a text editor, create a JavaScript file called gtmScheduler.js. Create a file with the following content:

                      function gtmScheduleController()
    {
       var   gtm_record = 'customrecord_ns_gtm_datalayer'
       ,   gtm_record_column = new nlobjSearchColumn('lastmodified')
       ,   gtm_record_list = nlapiSearchRecord(gtm_record, null, null, gtm_record_column) || [];
       
       gtm_record_list.forEach(function(record)
       {
    
          var record_saved_date = nlapiStringToDate ( record.getValue('lastmodified'), 'datetime').getTime()
          ,   current_date = new Date().getTime();
    
          if(current_date - record_saved_date <= 3600) {
             nlapiDeleteRecord(gtm_record, record.id);
          }
    
       });
    } 
    
                    
  2. Save the file in any accessible location.

To create the scheduler script:

  1. In NetSuite, upload your script file.

    1. Go to Customization > Scripting > Scripts > New.

    2. In the Scripts File field, click the Plus icon (+).

    3. Click Choose File.

    4. Go to your local files to select the gtmScheduler.js file.

    5. Click Open.

    6. Click Save.

  2. Create the script record.

    1. Click Create Script Record.

    2. Click Scheduled.

    3. In the Name field, enter: SC GTM Scheduler.

    4. In the ID field, enter: _ns_gtm_scheduler_script.

    5. On the Scripts tab, in the Function field, enter: gtmScheduleController.

    6. On the Deployments tab, click Add.

    7. Enter the following field values:

      Field

      Value

      Title

      GTM Scheduled

      ID

      _ns_gtm_scheduler_script

      Deployed

      Enable

      Status

      Scheduled

      Start Date

      Enter the date you want to start this scheduler

      Start Time

      Enter the time you want to start this scheduler

      Period

      Period

      Frequency

      Day

    8. Click Save.

  3. Click Deploy Script.

Related Topics

Google Tag Manager
Modify Google Tag Manager Services
Supported Google Tag Manager Services
Tracked Events
Set Up Google Tag Manager (SuiteCommerce Advanced Aconcagua and Earlier)

General Notices