How to Get Google Tag Manager working with PinnacleCart

This article will show you how to take Google Tag Manager and get it working with your PinnacleCart store. If you haven't already, you will need to initially setup Google Tag Manager, which you can find a walkthrough for at How to Setup Google Tag Manager. Once setup, you can proceed with the steps in this article.

Applies to Version(s): 3.8.0 - Current

Complexity Level: Advanced

Estimated Time for Completion: 2 hours

How to Add the GTM HTML Snippet to Your Store.

With the GTM HTML Snippet copied, go ahead and login to the admin area of your cart.

Click Search at the top right, search for File Manager and select it.

Navigate through the following path in your File Manager: content/engine/design/templates/wrappers/

Click the link to edit default.html.

Go ahead and highlight all the text in this file and paste it into a plain text program like Notepad++, Microsoft Notepad, or TextWrangler for Mac. Save it as default.html.

In the new file, we need to enter the GTM snippet in right after the opening body tag. The line you're looking for is:

<body id="page-{$current_page|htmlspecialchars}" class="page page-{$current_page|htmlspecialchars}">

Before pasting in the code, you will need literal tags. Enter a new line after the line above. Type out: {literal}{/literal}.

The GTM code would be pasted directly in between those literal tags, like:

{literal}<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->{/literal}

Save the file again.

Return to your File Manager, and this time navigate to: content/skins/_custom/skin/templates/wrappers. Click Upload File and upload the default.html file you saved.

We will need to load the file into your cache directory. To do this, just go to Design > Cart Designer. You can exit Cart Designer after it loads.

How to Add Conversion Code to Your Store.

Now you will need to add some code to your completed page to track conversions.

Go back to your File Manager.

Navigate to content/cache/skins/YOURSKIN/templates/pages/checkout and open up completed.html. Copy all of the text, return to your plain text editor and paste it in. Save the file as completed.html.

Note: Replace YOURSKIN in the path above with your actual skin name.

Highlight and copy the following code:

<script>
       var items = {$items|json_encode}
       dataLayer = [{literal}{{/literal}
           'event': 'company.transaction',
           'transactionId': '{$order_num}',
           'transactionAffiliation': 'Your Company Name',
           'transactionTotal': '{$order_total|string_format:"%.2f"}',
           'transactionTax': '{$tax|string_format:"%.2f"}',
           'transactionShipping': '{$shipping_amount|string_format:"%.2f"}',
           'transactionProducts': [
               {foreach from=$items item="item"}
               {literal}{{/literal}
                          'sku': '{if $item.attribute_sku != ''}{$item.attribute_sku|escape:"javascript"}{elseif $item.sku !=''}{$item.sku|escape:"javascript"}{else}{$item.product_id|escape:"javascript"}{/if}',
                           'name': '{$item.product_name|escape:"javascript"}',
                           'category': '{$item.catalog_name|escape:"javascript"}',
                           'price': '{$item.price|string_format:"%.2f"}',
                           'quantity': '{$item.quantity}'
           {literal}}{/literal},
               {/foreach}
           ]
       {literal}}{/literal}];
</script> 

Return to the completed.html file you created and create a new line after line 1, <div class="page-completed wrap {class file=$smarty.template editable=true}">. On line 2, paste in the code you copied above.

Replace 'company' in line 4 with your actual company name. Replace 'Your Company Name' with your actual company name on line 6 (after 'transactionAffiliation'). Save the file.

Back in your file manager, navigate to content/skins/_custom/skin/templates/pages/checkout/, click Upload File, and upload your completed.html file.

To push to cache, click Design > Cart Designer. Exit Cart Designer right after.

Adding Code For Assigning PinnacleCart Variables to GTM Variables.

The final piece of code you need to add will allow Google to translate it's variables into PinnacleCart. It will also allow events from specific pages or button clicks to be tracked on Google's side.

Go back to your File Manager.

Navigate to content/cache/skins/YOURSKIN/templates/layouts/zones and open up footer.html. Copy all of the text, return to your plain text editor and paste it in. Save the file as footer.html.

Note: Replace YOURSKIN in the path above with your actual skin name.

Highlight and copy the following code:

<script>
    dataLayer.push({literal}{{/literal}
      'current-page-type' : '{$current_page}',
        {if $current_page == 'home'}

        {/if}

        {if $current_page == 'catalog'}
            'store-cat-id' : '{$category.id}',
            'store-cat-name' : '{$category.name}',
            'store-cat-key' : '{$category.key}',
            'store-cat-level' : '{$category.level}',
            'store-cat-path' : '{$category.category_path}'
        {/if}

        {if $current_page == 'product'}
            'store-prod-name' : '{$product.title}',
            'store-prod-id' : '{$product.pid}',
            'store-prod-prodid' : '{$product.product_id}',
            'store-prod-price' : '{$product.price}',
            'store-prod-cat' : '{$product.cat_name}',
            'store-prod-image' : '{$GlobalHttpUrl}/{$product.image}',
            'store-prod-manufacturer' : '{$prdouct.manufacturer_name}'
        {/if}

        {if $current_page == 'cart'}

        {/if}

        {if $current_page == 'one_page_checkout'}

        {/if}

        {if $current_page == 'completed'}
            'store-completed-ordernum' : '{$order_num}',
            'store-completed-ordervalue' : '{$order_value}',
            'store-completed-ordertotal' : '{$order_total}'
        {/if}
    {literal}}{/literal});

</script> 

Return to the footer.html file you created and create a new line at the very bottom. Paste in the code you copied above and Save the file.

Back in your file manager, navigate to content/skins/_custom/skin/templates/layouts/zones/, click Upload File, and upload your footer.html file.

To push to cache, click Design > Cart Designer. Exit Cart Designer right after.

Creating Variables in GTM.

Now you will need to create the variables in Google Tag Manager so complete the connection. Return back to your GTM account. Click Variables on the left side.

First, under Built-In Variables, click Configure and make sure Page URL, Page Hostname, Page Path, and Referrer are selected. Under Utilities, select Event. And under Clicks, select Click Classes. Click Classes will allow you to add the Add to Cart click as an event.

Under User-Defined Variables, click New. For each of these variables, you will choose Data Layer Variable. The name of the variable and the Data Layer Variable Name will be exactly the same. Create Data Layer variables with the following names:

current-page-type
store-cat-id
store-cat-key
store-cat-level
store-cat-name
store-cat-path
store-completed-ordernum
store-completed-ordertotal
store-completed-ordervalue
store-prod-cat
store-prod-id
store-prod-image
store-prod-manufacturer
store-prod-name
store-prod-price
store-prod-prodid

Creating Page View Events and Conversion Events in GTM.

We can now add Events that occur on your store into GTM. This will be done in the form of triggers.

Visitor to Your Site.

  1. Click Triggers on the left. Click New.
  2. Name this Trigger Visitor.
  3. For Event, select Page View. Select Page View for the Trigger Type as well.
  4. Click Continue.
  5. For Fire On, select All Page Views.
  6. Click Create Trigger.

Checkout Conversion.

  1. Click Triggers on the left. Click New.
  2. Name this Trigger Conversion.
  3. For Event, under Page View select DOM Ready.
  4. Select Some DOM Ready Events.
  5. Choose Page URL, contains, and type completed.
  6. Click Save.

Creating Add to Cart Event in GTM.

Add to Cart Events will help with any tags you use the track this event, such as the Facebook Pixel. This is also done in triggers. You will want to specify which page the Add to Cart button is being clicked, since both product and category pages can contain an Add to Cart button.

Product Page Add to Cart Button Event.

  1. Click Triggers on the left. Click New.
  2. Name this Trigger Add to Cart Product Page.
  3. For Event, select Click.
  4. Select All Elements for the Target.
  5. Click Continue.
  6. For Fire On, select Some Clicks.
  7. Select Click Classes, contains, and type button-add-to-cart.
  8. Click the + button.
  9. Select current-page-type, equals, and type product.
  10. Click Create Trigger.

Catalog Page Add to Cart Button Event.

  1. Click Triggers on the left. Click New.
  2. Name this Trigger Add to Cart Catalog Page.
  3. For Event, select Click.
  4. Select All Elements for the Target.
  5. Click Continue.
  6. For Fire On, select Some Clicks.
  7. Select Click Classes, contains, and type button-add-to-cart.
  8. Click the + button. Select current-page-type, equals, and type catalog.
  9. Click Create Trigger.

Next Up.

The connection between Google Tag Manager and your PinnacleCart store is now complete. You are ready to start adding tags into GTM and they will automatically work within PinnacleCart. See the links below for some of these. After you've added all of your tags, you can view if they're working by clicking the Publish arrow at the top right and selecting Preview. When you navigate to your site, you will have a preview window at the bottom showing which tags are firing on specific pages. When satisfied, you can push this live by clicking Publish in GTM.

Links to Related Articles.

How to Add Google AdWords to Google Tag Manager.

How to Add Google Analytics to Google Tag Manager.

How to Add Facebook Pixel to Google Tag Manager.

How to Add Perfect Audience to Google Tag Manager.

Google Tag Manager.

If you didn't get your question answered, please contact the Pinnacle Cart Support Team. To submit a ticket, go to the My Account drop-down menu at the top right of the admin area and select Support

Was this article helpful?
0 out of 0 found this helpful