简体   繁体   English

Google跟踪代码管理器虚拟页面视图

[英]Google Tag Manager Virtual Page View

I have a little problem setting up a virtualPageView which should override the URL which is sent to google when no result is present. 我在设置virtualPageView时遇到一点问题,该方法应覆盖没有结果时发送给google的URL。

Heres what I have as JavaScript code: 这是我作为JavaScript代码所拥有的:

function returnNoSearchResultsGoogleTagManagerCode($searchterm){
    if ($searchterm == "") return "";

    $requestUri = $_SERVER['REQUEST_URI'] . "&no_result=".$searchterm;


    $js = "<script>
        $(document).ready(function(){
             dataLayer.push({
                 'event':'empty_result',
                 'virtualPageURL':'".$requestUri."'
                });
            });


    </script>";

    return $js;
}

As you can see, I want to use an event trigger (empty_result). 如您所见,我想使用事件触发器(empty_result)。

In google, I use a Trigger to determine if the Page is a no result Page. 在谷歌,我使用触发器来确定该页面是否为无结果页面。 First i created a custom Variable with custom JS 首先,我使用自定义JS创建了自定义变量

    function(){
       if (document.getElementsByClassName('ga-no-result').length > 0){
            return true;
       }else{
            return false
       }
   }

The class is set, if the SearchEngine can't find a result. 如果SearchEngine找不到结果,则设置该类。 So far so good. 到现在为止还挺好。 I also created a dataLayer variable to hold the virtualPageURL 我还创建了一个dataLayer变量来保存virtualPageURL

dataLayer

Now I need an event which is triggered if the variable is true. 现在,我需要一个变量为true时触发的事件。

事件SearchEmptyResult

Finally I created a Tag with type PageView which is fired when the event occurs: 最后,我创建了一个类型为PageView的Tag,该标签在事件发生时触发:

谷歌标签

Until now it seems okay, the Tag is properly configured (i guess) but if I do a search which has no result, the Page URL is not overridden 到现在为止,似乎已经正确配置了标记(我想),但是如果我进行的搜索没有结果, 则不会覆盖页面网址

在此处输入图片说明

The Tag is properly fired and the variables are filled. 已正确触发代码并填充了变量。 The overview of the dataLayer shows a correct dataLayer event. dataLayer的概述显示了正确的dataLayer事件。 But the PageURL is not overridden... Even if I wait a whole day, the category isn't sent to google. 但是PageURL不会被覆盖...即使我等了一整天,该类别也不会发送到google。

What am I doing wrong? 我究竟做错了什么? I would be very thankful if someone would have an idea or even a solution :) 如果有人有想法甚至解决方案,我将非常感激:)

Thanks in advance 提前致谢

exa.byte exa.byte

UPDATE: 更新:

Hey, I forgot to mention, that I want to use the new page variable as the string which google should use to determine the searchterm and the searchcategory In Google Analytics I configuered the search as the "q" parameter and the "no_result" as the category. 嘿,我忘了提一下,我想将新的页面变量用作Google应该用来确定搜索词和搜索类别的字符串。在Google Analytics(分析)中,我将搜索配置为“ q”参数,将“ no_result”配置为类别。 Is it even possible to change the string which google will parse in the end? 甚至可以更改Google最终解析的字符串吗?

To send a virtual pageview to Google Analytics, the field you need to change is page not {{Page Url}} , also the title field is often used. 要将虚拟综合浏览量发送到Google Analytics(分析),您需要更改的字段是page not {{Page Url}} ,而且经常使用title字段。

That's really the only two things you need to do to send a simple virtual pageview. 这实际上是发送简单的虚拟综合浏览量所需要做的两件事。

Extra: I always start my pagepath with /virtual/ to be able to recognize which ones are virtual pageviews easily in GA 额外:我总是以/ virtual /开头我的页面路径,以便能够在GA中轻松识别哪些是虚拟页面浏览量

For virtual page view you have to change Field "page" - in your GTM-OnSearchEmptyResult you are changing "{{Page URL}}" - I don't think that's correct way to send virutal pageview. 对于虚拟页面视图,您必须更改“页面”字段-在您的GTM-OnSearchEmptyResult中,您要更改“ {{页面URL}}”-我认为这不是发送虚拟页面视图的正确方法。 Also if you need to change hostname use Fieldname "hostname". 另外,如果您需要更改主机名,请使用字段名“主机名”。

In preview mode you will not see Page URL changed in Variables Tab, you have to go to the actual GA tag that is fired and check it's values. 在预览模式下,您不会在“变量”选项卡中看到页面URL更改,您必须转到实际触发的GA标签并检查其值。 You can either do this in GTM's preview tool or you can use standard developer tools - Network Tab and see what values are being sent to GA: 您可以在GTM的预览工具中执行此操作,也可以使用标准的开发者工具-网络标签,查看正在向GA发送哪些值:

在此处输入图片说明

You can see "dl" parameter is the current page, if you set up virtual page you should also see parameter called "dp" this is going to be the new value of page in your GA. 您可以看到“ dl”参数是当前页面,如果您设置虚拟页面,您还应该看到名为“ dp”的参数,这将成为您GA中页面的新值。

If you want to setup virtual pageview you have to use page instead of {{Page URL}} in your fieldname and for Document title use title in you fieldname. 如果要设置虚拟综合浏览量,则必须在字段 名称中使用页面而不是{{Page URL}},对于文档 标题 ,请在字段名称中使用title for more field reference of google analytics follow below link https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitType . 有关Google Analytics(分析)的更多字段参考 ,请点击以下链接https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#hitType

If you don't want to mess around with custom Tag Manager events it's still possible to use the good old ga method, even if you don't include the Analytics code on the page. 如果您不想弄乱自定义标签管理器事件,即使您没有在页面上包含Google Analytics(分析)代码,仍然可以使用旧的ga方法。 You just need to fetch the right tracker dynamically, as explained by Simo Ahava in this thread . 您只需要动态获取正确的跟踪器,如Simo Ahava在此线程中所述

if (typeof ga === "function") {
  ga.getAll().forEach((tracker) => {
    tracker.set('page', '/my/path'); // <- change here
    tracker.send('pageview');
  });  
}

I also put it in a gist here . 我也把它放在这里

thanks for your help. 谢谢你的帮助。 I think I got rid of the Problem and have solved it now. 我想我摆脱了问题,现在已经解决了。 I will describe my solution below: 我将在下面描述我的解决方案:

The solution is quite simple. 解决方案非常简单。

  1. I had an error/ spelling error @ google backend. 我在Google后端有一个错误/拼写错误。 I set the search_category parameter to "no_results", but used "no_result" for implementation... Pretty dumb, but sometimes you just won't see the wood for the trees... 我将search_category参数设置为“ no_results”,但是使用“ no_result”进行实现...相当愚蠢,但是有时您只是看不见树木的木头...

  2. I created a new Trigger as helper "HelperDomReady" to trigger the only if DOM is ready and the variable "isEmptySearch" equals "(bool)true" 我创建了一个新的触发器作为助手“ HelperDomReady”,以仅在DOM准备就绪且变量“ isEmptySearch”等于“(bool)true”时触发

Now I can see the searchterms which have no result in google backend in the "sitesearch categories" summary. 现在,我可以在“ sitesearch类别”摘要中看到在Google后端没有结果的搜索词。 Since I won't set the parameter at all, if the search had at least one hit, the site-search category shows "not-set" for successful results. 由于我根本不会设置该参数,因此,如果搜索至少有一个命中,则站点搜索类别将显示“未设置”以表示成功的结果。 Therfore the category-section will only show searches without a hit. 因此,类别部分将仅显示未命中的搜索。 Problem solved :) 问题解决了 :)

Disadvantage: The searchterm is also listed in the normal list. 缺点:搜索项也列在常规列表中。 But I think this is negligible 但是我认为这可以忽略不计

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google跟踪代码管理器虚拟页面视图不适用于链接中包含跨度标签或图像的链接 - Google tag manager virtual page view not working for links that have span tags or images inside the link 谷歌标签管理器虚拟浏览量 - google tag manager virtual pageview 如何在 Angular 中将页面查看事件发送到 Google 跟踪代码管理器 - How to send Page View Event to Google Tag Manager in Angular 在Google跟踪代码管理器中以当前页面浏览量设置广告系列 - Set campaign with current page view in Google tag manager 在 Google 跟踪代码管理器和 Google Analytics 4 (GA4) 中手动触发 page_view 的规范方法是什么? - What is the canonical way to manually fire page_view in Google Tag Manager and Google Analytics 4 (GA4)? 使用Google跟踪代码管理器将综合浏览量发送到虚拟URL到Google Analytics(分析) - Send pageview to virtual URL with google tag manager to google analytics Google跟踪代码管理器表单-谢谢页面 - Google Tag Manager Form - Thank You Page 谷歌标签管理器脚本降低页面性能 - Google Tag Manager Script reducing page performance Google 跟踪代码管理器 - 产品页面上的图像跟踪 - Google Tag Manager - Image Tracking on product page Google跟踪代码管理器显示空白页 - Google Tag Manager display blank page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM