Since GTM doesn't support document.write() method the standard clicktale code doesn't work. Is there a workaround for this?

ClickTale employee has sent me these instructions:

Replace the document.write JS line above with the following: 

<!-- ClickTale Bottom part --> 
<script type='text/javascript'> 
var externalScript = document.createElement('script');
var scrSrc = document.location.protocol=='https:'?

scrSrc += 'www11/ptc/xxx-xxx-xxx-xxx.js';

externalScript.src = scrSrc;
externalScript.type = 'text/javascript';
<!-- ClickTale end of Bottom part -->

I am not sure what to do with this. Has someone tried something like this?

  • I'm not sure about using Clicktale w/ Google Tag Manager. I've heard there's issues with it. I know Mouseflow (mouseflow.com) is fully compatible, though. Jun 11, 2013 at 20:17
  • @TrentScott, thanks. actually, I am looking for a tool to track web form submissions and funnels
    – Cubius
    Jun 12, 2013 at 6:33

2 Answers 2



I actually ran into the same issue and recently contacted ClickTale Support to find out the correct solution. I was given the following instructions which worked for me. Try the following:

1) Create a new tag in your GTM container.

2) Copy and paste the code into the new tag.

3) Change the general parameters in the code (PID, Ratio, PartitionPrefix) to your project’s details. For example (12345, 0.33, “www14”)

4) Save the new tag and publish the updated version of the container.

Here is the code:

<script type="text/javascript">
function ClickTaleCreateDOMElement(tagName) {
if (document.createElementNS) {
return document.createElementNS('http://www.w3.org/1999/xhtml', tagName);
return document.createElement(tagName);
var ClickTaleIsXHTMLCompliant = true;
var ClickTalePrevOnReady;
if (typeof ClickTaleOnReady == 'function') {
ClickTalePrevOnReady = ClickTaleOnReady;
ClickTaleOnReady = undefined;
var ClickTaleOnReady = function() {
window.ClickTaleScriptSource = (document.location.protocol == 'https:'?

window.ClickTaleIncludedOnDOMReady = true;
window.ClickTaleSSL = 1;

ClickTale(PID, Ratio, PartitionPrefix);

if(typeof ClickTalePrevOnReady == 'function') {
(function() {
var div = ClickTaleCreateDOMElement("div");
div.id = "ClickTaleDiv";
div.style.display = "none";

var externalScript = ClickTaleCreateDOMElement("script");
externalScript.src = document.location.protocol == 'https:'?

externalScript.type = 'text/javascript';

The correct way to do it is explained in http://wiki.clicktale.com/Article/Google_Tag_Manager_Integration

The procdeure is:

  • Create a new container (or add the below to an existing container).
  • Create a new Custom HTML tag in your GTM container.
  • Copy and paste your project’s bottom code (from the ClickTale account) into the new tag.
  • Check the “Support document.write” checkbox.

I tried it and it worked. Anyway I had to wait 24h (probably it's the time that Google needs for publishing the tag).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.