Jump to content
rudolfl

Google Tag Manager

Recommended Posts

Why do not propose a module in header tag ?



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

Sorry to say this, but personally I would not use this as it means core code changes, which oscommerce are trying to stop.  Eliminating unnecessary core code changes will make any future updates so much easier. Lets all pull in the same direction and try to help those coders that are working on making this software better.

 

Spend a few minutes and make it into a module so it conforms to what others are doing. If like me you are not a coder, ask one for a bit of help in converting this, I am sure they will give free help if they think its worthwhile.

Edited by 14steve14

REMEMBER BACKUP, BACKUP AND BACKUP

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

There the module make vey quickly (on the fly)  :)

I let you to update your module.

class ht_google_tag_manager {
var $code;
var $group;
var $title;
var $description;
var $sort_order;
var $enabled = false;

function ht_google_tag_manager() {
$this->code = get_class($this);
$this->group = basename(dirname(__FILE__));
$this->title = MODULE_FOOTER_GOOGLE_TAG_MANAGER_TITLE;
$this->description = MODULE_FOOTER_GOOGLE_TAG_MANAGER_DESCRIPTION;

if ( defined('MODULE_FOOTER_GOOGLE_TAG_MANAGER_STATUS') ) {
$this->sort_order = MODULE_FOOTER_GOOGLE_TAG_MANAGER_SORT_ORDER;
$this->enabled = (MODULE_FOOTER_GOOGLE_TAG_MANAGER_STATUS == 'True');
}
}

function execute() {
global $oscTemplate;


if (!empty(MODULE_FOOTER_GOOGLE_TAG_MANAGER_NUMBER)) {

$footer_tag = '<!-- google tag manager start -->'."\n";

$footer_tag .= '<noscript>';
$footer_tag .= '<iframe src="//www.googletagmanager.com/ns.html?id=' . MODULE_FOOTER_GOOGLE_TAG_MANAGER_NUMBER . '" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
$footer_tag .= '<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\',\'' . MODULE_FOOTER_GOOGLE_TAG_MANAGER_NUMBER . '\');';
$footer_tag .= '</script>'."\n";

$footer_tag .= '<!-- google tag manager end -->'."\n";

$oscTemplate->addBlock($footer_tag, 'footer_scripts');
}
}

function isEnabled() {
return $this->enabled;
}

function check() {
return defined('MODULE_FOOTER_GOOGLE_TAG_MANAGER_STATUS');
}

function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Category Title Module', 'MODULE_FOOTER_GOOGLE_TAG_MANAGER_STATUS', 'True', 'Do you want enable this module ?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insert he google tag number', 'MODULE_FOOTER_GOOGLE_TAG_MANAGER_NUMBER', '', Googletag number', '6', '0', now())");


tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_FOOTER_GOOGLE_TAG_MANAGER_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}

function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_FOOTER_GOOGLE_TAG_MANAGER_STATUS', 
'MODULE_FOOTER_GOOGLE_TAG_MANAGER_NUMBER', 
'MODULE_FOOTER_GOOGLE_TAG_MANAGER_SORT_ORDER');
}
}
Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

Google recommends putting GTM code right after opening <body> tag. This is why I did not use header tags module -- I wanted to make sure it gets into exactly right place.

Yes, I know, it will work in other places as well, but this may break some tags in the future. Better stick with recomendation.

 

Also, there may be other modules/code that use GTM datalayer. One has to make sure, datalayer is initialised first.

 

Rudolf

Edited by rudolfl

Share this post


Link to post
Share on other sites

Do you have the link for this recommandation



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

Ok I understand, https://developers.google.com/tag-manager/quickstart

 

It's also interesting to include the ecommerce : https://developers.google.com/tag-manager/enhanced-ecommerce

 

For Header, new version of the module (must work) to include in modules/content/header

class cm_header_google_tag_manager {
var $code;
var $group;
var $title;
var $description;
var $sort_order;
var $enabled = false;

function cm_header_google_tag_manager() {
$this->code = get_class($this);
$this->group = basename(dirname(__FILE__));
$this->title = MODULE_HEADER_GOOGLE_TAG_MANAGER_TITLE;
$this->description = MODULE_HEADER_GOOGLE_TAG_MANAGER_DESCRIPTION;

if ( defined('MODULE_HEADER_GOOGLE_TAG_MANAGER_STATUS') ) {
$this->sort_order = MODULE_HEADER_GOOGLE_TAG_MANAGER_SORT_ORDER;
$this->enabled = (MODULE_HEADER_GOOGLE_TAG_MANAGER_STATUS == 'True');
}
}

function execute() {
global $oscTemplate;


if (!empty(MODULE_HEADER_GOOGLE_TAG_MANAGER_NUMBER)) {

$header_tag = '<!-- google tag manager start -->'."\n";

$header_tag .= '<noscript>';
$header_tag .= '<iframe src="//www.googletagmanager.com/ns.html?id=' . MODULE_HEADER_GOOGLE_TAG_MANAGER_NUMBER . '" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
$header_tag .= '<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\',\'' . MODULE_HEADER_GOOGLE_TAG_MANAGER_NUMBER . '\');';
$header_tag .= '</script>'."\n";

$header_tag .= '<!-- google tag manager end -->'."\n";

$oscTemplate->addBlock($header_tag, $this->group);
}
}

function isEnabled() {
return $this->enabled;
}

function check() {
return defined('MODULE_HEADER_GOOGLE_TAG_MANAGER_STATUS');
}

function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Category Title Module', 'MODULE_HEADER_GOOGLE_TAG_MANAGER_STATUS', 'True', 'Do you want enable this module ?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insert he google tag number', 'MODULE_HEADER_GOOGLE_TAG_MANAGER_NUMBER', '', Googletag number', '6', '0', now())");


tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_GOOGLE_TAG_MANAGER_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.<br /> <strong>Must to be just after the <body> balise</strong>', '6', '0', now())");
}

function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array('MODULE_HEADER_GOOGLE_TAG_MANAGER_STATUS', 
'MODULE_HEADER_GOOGLE_TAG_MANAGER_NUMBER', 
'MODULE_HEADER_GOOGLE_TAG_MANAGER_SORT_ORDER');
}
}
Edited by Gyakutsuki


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

 

Share this post


Link to post
Share on other sites

I am planning to develop Google Analytics Enchanced eCommerce code that uses GTM Data Layer.

Few month ago, I did the GA module that uses "ga" to push the information to Google Analytics, but i find that GTM is a better way to manage all of it.

 

Rudolf

Share this post


Link to post
Share on other sites

but i find that GTM is a better way to manage all of it.

 

Rudolf

Why exactly ?

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

GTM replaces many other code snippets that every website grows over the years. This includes AdWords conversion trackig, Google Analytics and others. Instead of changing the code, one can just add a tag via GTM and it all works. Makes website clean. There are alos many other things, like custome events, etc.. that can be set up in GTM.

 

An example -- I want to set up Google Analytics. In case of osCommerse, I will have to go and install corresponding header tag. In case of other website, it will be a matter of installing a plugin or manually changing the code.

If GTM is installed, you simply add the corresponding tag via Tag Manager Interface at Google and all is working. Basically, lots of development is replaced by a single interface that can be sed by non-developers.

 

I suggest you read up and watch video of what GTM can do for you. I am no expert (not yet), but I do like what I learned about it.

 

Rudolf

Share this post


Link to post
Share on other sites

@@rudolfl

Thanks for your insight, I'll add it to my toread/todo list :D


KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Share this post


Link to post
Share on other sites

It's Googles way of centralising all the different "departments" of what they offer to site owners.  

We've been using it on a (ultra cutting edge) site for a little while and it works very well.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

It's Googles way of centralising all the different "departments" of what they offer to site owners.  

We've been using it on a (ultra cutting edge) site for a little while and it works very well.

 

This shop wanted to set up Trusted Stores....

 

I wasn't 100% sure how to do it - as it's not part of the remit of osCommerce - a quick google reveals;

https://support.google.com/trustedstoresmerchant/answer/6102723

 

And Trusted Stores is up and running, with no changes at the osC shop.

 

GTM is pretty cool.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Where should the code be pasted on a 2.2 ms2 install?  Header or footer maybe?


Quidquid latine dictum sit, profundum viditur.

Share this post


Link to post
Share on other sites

Google recommends putting GTM code right after opening <body> tag. This is why I did not use header tags module -- I wanted to make sure it gets into exactly right place.

 

It would be a content module in the navigation group. 


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Where should the code be pasted on a 2.2 ms2 install?  Header or footer maybe?

 

Find where the <body> is located in your 2.2 code and paste the GTM code (as shown at Google) right after it.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Are "googletags" related to a Google advertising offering, such as Adsense, Adwords, etc.?  If so, how do you monitor (and control) the quality of what Google is sending you for on-page advertising? I bring this up because on a couple of technology-oriented sites I visit from time to time, there are banner ads (constantly changing) that are often absurd. They are pure clickbait that I won't even waste a second on, but I'm sure they appeal to someone. An example: an obviously photoshopped, hideous picture of Hillary Clinton with a caption promising a look at her "hit list". Now, I understand that some people just hate her guts and are anxious to click to get the latest dirt on the Hildebeast, but I'm guessing it's something totally different from what was promised (including drive-by malware downloads). Other examples: breathless "doctors astounded by _____", "scientists amazed by _____", a picture of two helicopters lifting a supertanker off a beach, a 40-storey high cruise liner (that looks unstable enough that the tiniest ripple would capsize it), a 777 airliner with the two engines replaced by passenger cabins and the central fuselage replaced by a huge jet engine,... well, you get the picture. These things are funny to look at, but I wouldn't want them despoiling my site. I assume that Google is involved somewhere because the page is loaded with "googletag" in the source. So, how does one keep control over the quality of ads being run on their site? Do reputable ad providers guarantee a certain level of quality and truthfulness, or is it the Wild West out there? Do any let you vet what they intend to run, before they run the ads?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×