Set Up GTM

This topic applies to

Applies to

SuiteCommerce Web Stores

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

Set up involves several steps in NetSuite and in Google applications. To set up Google Tag Manager for SuiteCommerce and SuiteCommerce Advanced (2018.2 and later), complete the steps shown in the figure below. Detailed procedures are provided below the figure.

Step

Description

Step 1: Install SC Google Tag Manager Editor.

This section provides instructions for installing Google Tag Manager Editor in your NetSuite account.

Step 2: Sign Up for GTM.

This section provides instructions for setting up a free Google Tag Manager account and creating your first container.

Step 3: Authenticate Your Site with the Google API.

This section provides instructions for adding your OAuth 2.0 GTM Client ID in NetSuite Company Preferences. This is required to authenticate with Google Tag Manager.

Step 4: Link your GTM Account to a Domain.

This section provides instructions for adding your GTM ID (created when you sign up for GTM) to your SuiteCommerce configuration record.

Step 5: Add Services to Your GTM Container.

This section provides instructions for adding services such Google Analytics, Google Ads, Bing Ads, Optimizely, Facebook and others to your GTM container. To complete this step, you must have an account for each service you are adding and must know the identifying information required to connect to each service.

Step 6: Review and Publish Your Changes.

This section provides instructions for previewing and publishing changes to your GTM account.

Step 7: Preserve GTM Session Data.

This section provides instructions for preserving session data.

Step 1: Install SC Google Tag Manager Editor

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

Step 2: Sign Up for GTM

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 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 GTM 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. In the Container Name field, enter your site name.

    Example: www.mysite.com

  8. In the Where to Use Container field, select Web.

  9. Click Create.

  10. Close the Install Google Tag Manager window.

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

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

Step 3: Authenticate Your Site with the Google API

Google requires you to authenticate your site with the Google API. A free Google OAuth Client ID accomplishes this requirement. To see if you already have an OAuth 2.0 client ID, log in to Google API Credentials Console using your Google account to view your existing credentials. If you do not already have a OAuth Client ID, see To get an OAuth Client ID.

To get an OAuth Client ID:

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

  2. Click Create credentials > OAuth client ID.

  3. On the credentials form, set the application type to Web application.

  4. Enter a Name for your OAuth Client ID.

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

    Your URIs must match the value of your NetSuite datacenter URIs (examples: https://system.netsuite.com and https://system.na3.netsuite.com).

To authenticate your site with the Google API:

  1. In NetSuite, go to Setup > Company > General Preferences > Custom Preferences > Google Tag Manager Editor.

  2. Enter your GTM (OAuth) Client ID.

  3. Click Save.

Step 4: Link your GTM Account to a Domain

Link your GTM ID to the SC Configuration record for the associated domain.

To link your GTM account to your domain:

  1. Go to Setup > SuiteCommerce Advanced > Configuration.

  2. Select your website and domain and click Configure.

  3. In the SuiteCommerce Configuration record, navigate 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 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, enable the Is A Multi-Domain Site option.

  6. Click Save.

Step 5: Add Services to Your GTM Container

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

To add services to your GTM 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.

  4. Click View on your container record.

  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 service for Google Analytics, 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.

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

Step 6: Review and Publish Your Changes

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

To review and publish your changes:

  1. From the Container Services page in the Google Tag Manager Editor, click Review and Publish Changes.

    This redirects you to your workspace and container in GTM.

  2. On the Google Tag Manager 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).

Step 7: Preserve GTM Session Data

Follow the steps in this section 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.

Step

Description

Enable SuiteScript and Custom Records

This procedure provides instructions for how to enable SuiteScript and custom Records in NetSuite.

Create a Custom Record

This procedure provides instructions for how to create a customer records used to store data between sessions.

Create Scheduler File

This procedure provides instructions for creating the scheduler file that deletes unneeded session data records every 60 minutes.

Create Scheduler Script

This procedure provides instructions for creating the scheduler script that executes every 60 minutes.

To enable SuiteScript and Custom Records:

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

  2. On the SuiteCloud tab, SuiteBuilder section, enable the Custom Records feature.

  3. On the SuiteCloud tab, SuiteScript section, enable these options:

    • 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 this custom record.

    Example: SC GTM DataLayer

  3. In the ID field, enter: _ns_gtm_datalayer.

    You must enter this value exactly as shown (including the underscore character at the front).

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

  5. Disable the Include Name Field option.

  6. Accept all other default values and click Save.

  7. On the Record Types page, locate and select the title of your new record type.

  8. On the Fields tab, add two new fields: gtm_id and gtm_events. Use the settings and values shown below.

    For information about how to add fields to a custom record type, see the help topic 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.

  2. Add the following content to this file:

    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); } }); }
  3. 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. Navigate 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 these 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.