Set Up Google Tag Manager

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 Google Tag Manager (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 Google Tag Manager.

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

Step 3: Authenticate Your NetSuite Account with the Google API.

This section provides instructions for creating your Google API OAuth client ID credentials, populating the required values for your Google API OAuth consent screen, and linking your Google API OAuth client ID to your NetSuite account.

Step 4: Link your Google Tag Manager Account to a Domain.

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

Step 5: Add Services to Your Google Tag Manager Container.

This section provides instructions for adding services such Google Analytics, Google Ads, Bing Ads, Optimizely, Facebook and others to your Google Tag Manager 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 Google Tag Manager account.

Step 7: Preserve Google Tag Manager 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 Google Tag Manager

To sign up for a Google Tag Manager 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 Google Tag Manager account, Google creates your Google Tag Manager 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 Google Tag Manager 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 Google Tag Manager code displayed in this window.

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

Step 3: Authenticate Your NetSuite Account with the Google API

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

  1. To create your Google API OAuth client ID credentials:.

  2. To provide values for your Google API OAuth consent screen:.

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

These steps only affect one NetSuite account. You only need to perform these steps one time.

To create your Google API OAuth client ID credentials:

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

  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. You must 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 following values:

    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.

To provide values for your Google API OAuth consent screen:

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.

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

  2. Click Credentials in the left navigation bar.

  3. Click the OAuth consent screen tab.

  4. Enter the following values:

    Field Name

    Value

    Details

    Application name

    NetSuite

    Application Logo

    Upload your company logo (optional).

    Support email

    <valid email address>

    Enter the email address of a 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 on the Edit OAuth client icon (pencil).

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

    Important

    Log in to your NetSuite account and make a note of your NetSuite account URL. You must 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. Select the Custom Preferences tab.

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

  4. Click Save.

Step 4: Link your Google Tag Manager Account to a Domain

Link your Google Tag Manager ID to the SuiteCommerce Configuration record for the associated domain.

To link your Google Tag Manager 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 Google Tag Manager 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 Google Tag Manager Container

Add supported service to your Google Tag Manager 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 Google Tag Manager 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 on 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 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 Google Tag Manager 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 Google Tag Manager, 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 Google Tag Manager.

  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 Google Tag Manager 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

To enable SuiteScript and Custom Records:

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

To create a custom record:

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

To create the scheduler file:

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

To create the 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.