I try to set a custom segment (not based on roles or profile data) on a single node with add_js, but drupal insert the set_var script over the google analytics script. And my custom segment isn't tracked.

Is it possible to change the weight or do something like custom snippets, but not for all the site, just 1 page?

Comments

hass’s picture

Category: feature » support
hass’s picture

Title: Is it posiible to add custom _setVar on a single node? » Is it possible to add custom _setVar on a single node?
Status: Active » Fixed

I think this is currently not possible and may never be as this would collide with profile tracking (set_var can only used once). You might get an idea how this may be possible if you read http://drupal.org/node/393070#comment-1326766, but your need to solve this yourself or by writing a custom module (like http://drupal.org/node/231451#comment-905484) - only for this one task.

This request may be seen as a duplicate of #231451: Add hook to alter data before sending it to browser.

Anonymous’s picture

I will try this:
Disable tracking code on this node (by url) and add the full tracking code with add_js.

What do you think?

hass’s picture

Not really. You cannot add the set_var via add_js... it will ever stay in a wrong position. The set_var line needs to come between var pageTracker = _gat._getTracker("UA-12345-1"); and pageTracker._trackPageview();. This is the main problem you can only solve today by creating a custom module or theme function that alters the footer code in the way you can see at http://drupal.org/node/231451#comment-905484.

hass’s picture

I have another idea... something that is ready :-).

Install the sections.module (latest DEV) and assign section to your node. Afterwards you can have a custom sections-page-[section-ID].tpl.php what will become a 1:1 copy of your current page.tpl.php. Than you exclude this node from tracking and add the tracking code by hand to sections-page-[section-ID].tpl.php.

Anonymous’s picture

Thank you for your suggestion, but I meant add the full tracking code, not just the setVar via add_js this way:

$ga_tracking_1 ='
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
';

$ga_tracking_2 ='
try {
var pageTracker = _gat._getTracker("UA-xxxx");
pageTracker._setVar('myVar');//<============
pageTracker._trackPageview();
} catch(err) {}
';

drupal_add_js($ga_tracking_1, 'inline', 'footer');
drupal_add_js($ga_tracking_2, 'inline', 'footer');

Anonymous’s picture

-

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.