Jump to content

Archived

This topic is now archived and is closed to further replies.

Queue-it

Adding experiment tracking code

Recommended Posts

Queue-it

Hi,

Where do I add the google experiment code for A/B testing so it would be above the original google analytics tracking code? 

1. I've tried to put in the Pagelines Advanced settings

2. and in the functions php file, but none of that worked. 

I'm using a SEO yoast plugin to connect wordpress with GA and there are no settings to add the code before the original one.

 

 

Share this post


Link to post
Share on other sites
Simon

Where in yoast are you adding GA code? I have never noticed this setting before

Share this post


Link to post
Share on other sites
Queue-it

I just have to connect Yoast with a press of a button, (and I have no control over where the code is set as it's done via plugin) and there is no such option for the experiment tracking code.

I tried adding it also to the header php file (as it should be before the original tracking code), but that crashed the site as well. 

Share this post


Link to post
Share on other sites
Simon

Can you screenshot in yoast where you are adding analytics, I have it installed on my blog, to test I need to replicate.

 

Share this post


Link to post
Share on other sites
Queue-it

Not sure how's that going to help.

This is the code that I can't find where to add, without crashing the site:


//Google Experiment Code
function google_experiment_code() {
    if( is_page(xxx) ) {
    ?><?php
    }
}
add_action( 'wp_head','google_experiment_code', 5 );
<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='30041124-5',d=document,l=d.location,c=d.cookie;
if(l.search.indexOf('utm_expid='+k)>0)return;
function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.
indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.
length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(
'<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':
'://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+
'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().
valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
</script><script>utmx('url','A/B');</script>
<!-- End of Google Analytics Content Experiment code -->
<?php
    }
}
add_action( 'wp_head','google_experiment_code', 5 );

 

ga.PNG

Share this post


Link to post
Share on other sites
Queue-it

Hi again,

I have to add the code below the top of the head section but where exactly should I do that? Which file should that be?

I've tried it via header php file and also using a plugin  but I can't get it validated by google analytics.

 

<?php if((is_page(15081)) || (is_page(695))) : ?>
  <!-- Google Analytics Content Experiment code -->

<!-- End of Google Analytics Content Experiment code -->
<?php else: ?>
   <!-- Google Analytics code -->

<!-- End of Google Analytics code -->

<?php endif; ?>
 

 

 

Share this post


Link to post
Share on other sites
Queue-it

Hey, 

We tried this, but it is adding both codes - the general and the experiment code to all pages instead of adding a general code to all pages and the experiment code only to two specif ones.

Otherwise the plugin setup seems to work, just not the tracking 

 

Share this post


Link to post
Share on other sites
Simon

It might help if you reveal these pages, the plugin works its simple.

It either shows the top snippet if the page id is in that array, or it shows the 2nd snippet if the page id isnt... there isnt much else to go wrong.

Share this post


Link to post
Share on other sites

  • Similar Content

    • Barnaby Skinner
      By Barnaby Skinner+
      Hey team,
      Really simple question: where would I add code to a specific page header? I can see in the settings I can add code to the global header, but can't see how to do it for a single specific page. It's related to facebook pixel tracking
      Cheers
    • navigador
      By navigador+
      If I'm using PL5 with PL5 Framework, what is the best way to include Google Analytics code?
       
      I know we have an Advanced section in Settings but that just allows for Header scripts. Should we also have a footer (after body) section to place scripts like GA.
       
    • dgsarnow
      By dgsarnow+
      I would like to add Google Analytics click tracking to the buttons on my site. I use the Pagelines shortcodes for the buttons. I was able to add the necessary header script easily using Custom Scripts.
       
      How can I insert the following onclick option to my buttons?
       
      onclick=”trackOutboundLink(‘http://www.domain.com’); return false;"          
    • atcdomainsolutions
      By atcdomainsolutions+
      Question:
      When adding Google Analytics to a site, it's best to add it into the Custom Javascript/Header HTML area (below the Custom LESS box) to ensure it is tracked on all pages, correct?
       
      If not, where should I add it?  
    • kboyle10
      By kboyle10
      I found this solution initially to this problem of placing tracking pixels on an individual page.
       
      http://forum.pagelines.com/topic/33149-tracking-code-on-a-specific-page-header/?hl=tracking
       
      However, the Pagelines Customize plug suggested does not work. I've already designed nearly my entire site with content and I don't know what installing a base theme is going to do to everything I've done. 
       
      Is there another solution or an update to the Paglines Customize plugin that I'm not seeing?
       
      Just for Information, the initial problem is:
       
      The ability to place a tracking pixel on an individual page to track a paid media buy. It can't be placed in the <head> of all pages or all the data will be worthless. It just needs to site on one single page. 
×