跨领域谷歌分析活动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨领域谷歌分析活动相关的知识,希望对你有一定的参考价值。

This script was written to allow transposing of utm_campaign, utm_source and utm_medium query parameters from the URL of a landing page link to all of the links on that page that re-directed to the primary domain where users would actually convert. This is highly useful when sending out email campaigns that link people to a landing page on a hosted service such as Unbounce and your conversion points exist on a different top-level domain as it will allow you to see the campaign, medium and source values on the top-level domain Google Analytics conversion reports, even though the visitor initially landed on a different top-level domain.
  1. /**
  2.  * URL link updater for cross-site UTM code transposing
  3.  *
  4.  * Update the validURLPattern variable regular expression to match your desired pattern
  5.  * that indicates link HREF values that go to the second-site.
  6.  */
  7. try {
  8. // URL pattern regular expression, change this to match your call to action links
  9. var validURLPattern = new RegExp("my-conversion-point-domain.com");
  10. // The search string
  11. var queryStr = document.location.search;
  12.  
  13. // Only update if we have UTM parameters
  14. if(queryStr.match(/utm_campaign|utm_source|utm_medium/)){
  15. // Build object of UTM parameters
  16. var utm = {
  17. campaign: queryStr.match(/utm_campaign/) ? queryStr.match(/utm_campaign=([^&]*)/)[1] : "",
  18. source: queryStr.match(/utm_source/) ? queryStr.match(/utm_source=([^&]*)/)[1] : "",
  19. medium: queryStr.match(/utm_medium/) ? queryStr.match(/utm_medium=([^&]*)/)[1] : ""
  20. };
  21.  
  22. // Loop through all A tags and update
  23. $('a').each(function(){
  24. // Only update if HREF matches the URL pattern
  25. if(this.href.match(validURLPattern)){
  26. // Determine starting separator
  27. var sep = this.href.indexOf("?") == -1 ? "?" : "&";
  28.  
  29. // Loop through UTM parameters to update
  30. for(var k in utm){
  31. // Check if URL already contains this UTM parameter
  32. if(this.href.indexOf("utm_" + k) != -1){
  33. var regexp = new RegExp("utm_" + k + "=([^&]*)");
  34. this.href = this.href.replace(regexp, "utm_" + k + "=" + utm[k]);
  35. }
  36. // Append if not
  37. else {
  38. this.href += sep + "utm_" + k + "=" + utm[k];
  39. // Change separator now since we're appending to a now existing query string
  40. sep = "&";
  41. }
  42. }
  43. }
  44. });
  45. }
  46. } catch(e) {}

以上是关于跨领域谷歌分析活动的主要内容,如果未能解决你的问题,请参考以下文章

启动谷歌地图意图后返回活动

跨活动的片段之间的共享元素转换不一致

活动和片段中的多个谷歌地图

getSupportFragmentManager() 在活动扩展片段中未定义

谷歌分析跨域跟踪转化推荐问题

谷歌地图在Android的标签片段上显示为灰色