设置自定义广告系列_setCampNameKey不能在Google Analytics ga.js中使用 [英] Setting Custom Campaign _setCampNameKey not working in Google Analytics ga.js

查看:112
本文介绍了设置自定义广告系列_setCampNameKey不能在Google Analytics ga.js中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我希望通过 ga.js 使用我的应用程序创建的一些自定义活动。我使用一些客户广告系列和所有广告系列信息,并创建该广告系列的哈希代码并将其放入网址中。我的营销活动网址看起来像

  http://mysite.com/?aff=eyJer5fg4IxOCIsInRleHRfbGlua19pZCI6IjgyIiwiY2FtcGFpZ25faWQiOiIxNCJ9 
mysite.com
时,我检查查询参数 aff 存在。如果是,那么我解码广告系列信息并尝试将其作为自定义广告系列发送。我的跟踪代码看起来像

 < script> 
var _gaq = _gaq || [];
_gaq.push(['_ setAccount','我的个人资料ID']);
_gaq.push(['_ trackPageview']);
_gaq.push(['_ setDomainName','mysite.com']);
<?php
if($ this-> campaignName!=''){
?>
_gaq.push(['_ setCampNameKey','<?php echo $ this-> campaignName?>']); //我的解码信息
_gaq.push(['_ setCampMediumKey', '<?php echo $ this-> campaignMedium?>']); //我的解码信息
<?php
}
?>
(function(){
var ga = document.createElement('script'); ga.type ='text / javascript'; ga.async = true;
ga.src =( 'https:'== document.location.protocol?'https:// ssl':'http:// www')+'.google-analytics.com / ga.js';
var s =文档.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga,s);
})();
< / script>

但是当某个用户通过点击上面的URL来访问mysite.com时, ga.js 不会跟踪广告系列。我检查了我的DOM, _setCampNameKey 被正确呈现。但它需要它作为推介。任何机构能告诉我我做错了什么?它是跟踪我的自定义广告系列还是其他方式的方式?

由于 _trackPageview 触发跟踪过程,您必须在 _trackPageview 命令之前放置 _set * 命令有效。


另一个解决方案是通过URL参数设置自定义广告系列



编辑:另请参阅这个问题的答案 _setCamp * Key 函数不直接设置该值,而是另一个包含该值的URL参数的名称。例如,您必须将广告系列名称放在一个单独的网址参数中,例如:

  http://mysite.com/? camp_name = My + Campaign 

然后您可以告诉GA, my_camp_name 包含广告系列名称:

  _gaq.push(['_ setCampMediumKey','camp_name']); 

就你而言,它可能会传递一个带有这些参数的自定义URL到 _trackPageview

  _gaq.push(['_ setAccount','my profile id']) ; 
_gaq.push(['_ setDomainName','mysite.com']);
_gaq.push(['_ setCampNameKey','camp_name']);
_gaq.push(['_ setCampMediumKey','camp_medium']);
_gaq.push(['_ trackPageview','http://mysite.com/?camp_name=<?php echo $ this-> campaignName?>& camp_medium =<?php echo $ this - > campaignMedium>']);?


Hello there I want to use some custom campaings created by my application through ga.js. I use some custome campaign and all campaign information and create a hash code of that campaign and put it in the url. My Campaigh URL looks like

http://mysite.com/?aff=eyJer5fg4IxOCIsInRleHRfbGlua19pZCI6IjgyIiwiY2FtcGFpZ25faWQiOiIxNCJ9

Now when user landed on mysite.com I check if query parameter aff exists. If yes then I decode the campaign information and try to send it as custom campaign . My tracking code looks like

 <script>
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'my profile id']);
 _gaq.push(['_trackPageview']);
 _gaq.push(['_setDomainName', 'mysite.com']);
 <?php
 if($this->campaignName != '') {
  ?>
  _gaq.push(['_setCampNameKey','<?php echo $this->campaignName?>']);//my decoded info
  _gaq.push(['_setCampMediumKey','<?php echo $this->campaignMedium?>']);//my decoded info
  <?php
  }
 ?>
 (function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();
</script>

But when some user comes to mysite.com by clicking the above url, ga.js don't track the campaign. I have checked my DOM that _setCampNameKey is properly rendered. But it takes it as referral. Can any body tell me what am I doing wrong? Is it the way to track my custom campaign or some other way to do?

解决方案

Since _trackPageview triggers the tracking process, you must put the _set* commands before the _trackPageview command to be effective.

Another solution is to setup custom campaigns via URL parameters.

Edit: Also see the answer to this question. The _setCamp*Key functions don't set the value directly but the name of another URL parameter which contains the value. For example, you have to put the campaign name in a separate URL parameter like:

http://mysite.com/?camp_name=My+Campaign

Then you can tell GA that the my_camp_name contains the campaign name:

_gaq.push(['_setCampMediumKey','camp_name']);

In your case, it might work to pass a custom URL with these parameters to _trackPageview:

_gaq.push(['_setAccount', 'my profile id']);
_gaq.push(['_setDomainName', 'mysite.com']);
_gaq.push(['_setCampNameKey','camp_name']);
_gaq.push(['_setCampMediumKey','camp_medium']);
_gaq.push(['_trackPageview', 'http://mysite.com/?camp_name=<?php echo $this->campaignName?>&camp_medium=<?php echo $this->campaignMedium?>']);

这篇关于设置自定义广告系列_setCampNameKey不能在Google Analytics ga.js中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆