I am trying to add a tracking javascript code (Similar to Google Analytics, but not) to a website. When I Add a block, add the tracking code, select Full HTML and themes footer, the code ends up showing up on the live website.

How can I add this code, so that it doesnt show up on the live site, but only in the source code.

Comments

Crystal_tracking created an issue. See original summary.

drumm’s picture

Project: Project issue tracking » Drupal core
Version: 7.x-2.x-dev » 7.x-dev
Component: Issues » block.module
cilefen’s picture

Adding JavaScript to a page via the Block UI is not a good idea. Use the recommended ways, the simplest being the theme .info file if you need the code on all pages.

Crystal_tracking’s picture

I FTP into the website and added the javascript code to the page.tpl.php file (right below the . I have yet to upload it, but I want to know if this is a good place before I do it.

cilefen’s picture

Always test changes on your staging server before pushing code to your live environment.

Crystal_tracking’s picture

I didn't develop the website, so I am not sure how to test on staging server. My responsibilities is to just add the javascript code.

cilefen’s picture

I showed you the recommended ways to add JavaScript. You went with something different, then you asked if that would be ok. The only way to be sure is to test on a staging server or cross your fingers and possibly break your live site.

cilefen’s picture

Crystal_tracking’s picture

To be honest, all of this if foreign to me. I've tried to look for the module/theme .info within the Drupal Control Panel, but nothing is standing out.

cilefen’s picture

The theme info file is a file on the filesystem that is inside the directory containing your theme files.

Crystal_tracking’s picture

Ok, can I edit the .info file by FTPing into the site? I FTP into the site and found a .info file in the themes file, Below is some of the code I see. I can just add javascript code to this file? I just want to make sure I am understanding the options you provided.

settings[omega_toggle_extension_assets] = 1
settings[omega_libraries][selectivizr][status] = 0
settings[omega_libraries][respond][status] = 0
settings[omega_libraries][pie][status] = 0
settings[omega_libraries][html5shiv][status] = 1
settings[omega_toggle_extension_development] = 0
settings[omega_rebuild_theme_registry] = 0
settings[omega_rebuild_aggregates] = 0
settings[omega_browser_width_indicator] = 0
settings[omega_livereload] = 0
settings[omega_livereload_script] = http://localhost:35729/livereload.js
settings[omega_livereload_host] = localhost
settings[omega_livereload_port] = 35729
settings[omega_demo_regions] = 0
settings[favicon_mimetype] = image/vnd.microsoft.icon

cilefen’s picture

This module may be more like what you need: https://www.drupal.org/project/tracking_code

Crystal_tracking’s picture

I downloaded the Recommend Releases for the Tracking Module, but I have no idea what to do with it.

cilefen’s picture