Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ChablaisWeb

    (@chablaisweb)

    Hi Tamas,

    It doesn’t work. Not lot of time this week. I keep the post open, I’ll try to find next week and come back here.

    😉

    Thread Starter ChablaisWeb

    (@chablaisweb)

    Hi Tamas,

    I understand your thought. In fact, I used about 2 or 3 tags by post. So for me, it’s useful to analyse tag as custom dimensions. And about categories, I have a main blog category and alwaysat least another more specific.

    I can try your solution and see. I’ve tried to modify php code without success. I was inspiring of this article (http://juliencoquet.com/en/2014/01/22/data-layer-google-tag-manager-for-wordpress/) from Julien Coquet where he explained how he sets a datalayer on his WordPress site. And he sets categories and tags in a way that he pulls strings, not array.

    Eventually, if your PHP skills are better than mine (not diffucult ^^), have you an idea for quick change ?

    Your code for tags :

    if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_TAGS ] ) {
    			$_post_tags = get_the_tags();
    			if ( $_post_tags ) {
    				$dataLayer["pageAttributes"] = array();
    				foreach( $_post_tags as $_one_tag ) {
    					$dataLayer["pageAttributes"][] = $_one_tag->slug;
    				}
    			}
    		}

    Julien’s code :

    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    $gtm_tags .= $tag->name . ‘ ‘;
    }
    }
    
    ‘GTM_WP_Tags': ‘<?php print trim($gtm_tags); ?>’

    And for category, your code :

    if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_CATEGORIES ] ) {
    			$_post_cats = get_the_category();
    			if ( $_post_cats ) {
    				$dataLayer["pageCategory"] = array();
    				foreach( $_post_cats as $_one_cat ) {
    					$dataLayer["pageCategory"][] = $_one_cat->slug;
    				}
    			}
    		}

    Julien’s code :

    $gtm_cat = get_the_category();
    ‘GTM_WP_Category': ‘<?php print $gtm_cat[0]->cat_name; ?>’

    If I made illusion to myself and there is no quick change (you know, in 2 seconds you see and say oh! ok he made like this. Bah, just do this in my php code and it’s done !) it’s ok, I’ll try the macro solution.

    Anyway, I thank you for support. Have a nice day.

    Thread Starter ChablaisWeb

    (@chablaisweb)

    I’ve forgotten. My website : http://www.chablais-web.Fr.

    And of course, I often assign multiple attributes and categories to my posts. That’s for it that I have the problem

    Regards !

Viewing 3 replies - 1 through 3 (of 3 total)