Adding analytic code

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Minnu
Posts: 22
Joined: Fri Aug 28, 2009 11:39 am

Adding analytic code

Post by Minnu »

Hi
I have to add the following code in the dita pages. This is to identify the usage ratio of help files. Please let me know how can I add this code and how it could be generated on every build?

The code:
<!-- Start Code for Xiti Analytics -->
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/configuration-stat.js"></script>
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/stat.js"></script>
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/stat-dpl.js"></script>
<script type="text/javascript">
pageStatInjection();
</script>
<!-- End Code for Xiti Analytics -->

Regards
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Adding analytic code

Post by sorin_ristache »

Hi,

You should add the script elements in the template

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
from stylesheet

Code: Select all

[Oxygen-install-dir]/frameworks/dita/DITA-OT/plugins/com.oxygenxml.webhelp/xsl/dita2webhelpImpl.xsl
This template is called once for every DITA topic file processed by the DITA Map WebHelp transformation.


Regards,
Sorin
Minnu
Posts: 22
Joined: Fri Aug 28, 2009 11:39 am

Re: Adding analytic code

Post by Minnu »

Hi Sorin
Thank you for the reply. I am using Oxygen XML 9.3, so dita2webhelp is not available and the xsl which i am using in dita2xhtml.xsl. Is it possible to add the script in this file and run?

Regards
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Adding analytic code

Post by sorin_ristache »

Hi Minnu,

In that case you should add your code in the same template

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
from the stylesheet

Code: Select all

[Oxygen-9.3-install-dir]/frameworks/dita/DITA-OT/xsl/xslhtml/dita2htmlImpl.xsl

Regards,
Sorin
Minnu
Posts: 22
Joined: Fri Aug 28, 2009 11:39 am

Re: Adding analytic code

Post by Minnu »

Hi
How do I add the script elements in the template? I have no idea about how to add code in the template. I am from english literature background. Please help.
Regards
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Adding analytic code

Post by sorin_ristache »

Hi,

Please open the following file for editing in the Oxygen application:

Code: Select all

[Oxygen-9.3-install-dir]/frameworks/dita/DITA-OT/xsl/xslhtml/dita2htmlImpl.xsl
and locate the line that contains the text:

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
You have to insert your code after that line, so that the file contains after your modification:

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
<!-- Start Code for Xiti Analytics -->
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/configuration-stat.js"></script>
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/stat.js"></script>
<script type="text/javascript" src="//${serverName}${contextPath}/js/xiti/stat-dpl.js"></script>
<script type="text/javascript">
pageStatInjection();
</script>
<!-- End Code for Xiti Analytics -->
</xsl:template>
Please note that you have to replace ${serverName}${contextPath} with the correct server name and path, because the HTML output file of the DITA Map XHTML transformation must contain a real Web address from where the JavaScript files which you want to add with the <script> elements (configuration-stat.js, stat.js. etc.) can really be loaded by a Web browser (IE, Firefox, Chrome, etc). After you save the dita2htmlImpl.xsl file just run the transformation DITA Map XHTML on your DITA map file for creating the output HTML files from your DITA XML topics.


Regards,
Sorin
Minnu
Posts: 22
Joined: Fri Aug 28, 2009 11:39 am

Re: Adding analytic code

Post by Minnu »

Hi Sorin
I have added the code as follows in the dita2htmlImpl.xsl file, but it didn't work!

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
<xsl:template name="gen-user-scripts">
<xsl:apply-templates select="." mode="gen-user-scripts"/>
</xsl:template>
<xsl:template match="/|node()|@*" mode="gen-user-scripts">
<!-- Start Code for Xiti Analytics -->
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript">
pageStatInjection();
</script>
<!-- End Code for Xiti Analytics -->
<!-- to customize: copy this to your override transform, add the content you want. -->
<!-- It will be placed before the ending HEAD tag -->
<!-- see (or enable) the named template "script-sample" for an example -->
</xsl:template>


Please let me know if there is anything wrong
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Adding analytic code

Post by sorin_ristache »

Hi Minnu,

The following lines should be removed from dita2htmlImpl.xsl:
Minnu wrote:

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
<xsl:template name="gen-user-scripts">
<xsl:apply-templates select="." mode="gen-user-scripts"/>
</xsl:template>

so that only the following fragment added by you remains in the dita2htmlImpl.xsl file:

Code: Select all

<xsl:template match="/|node()|@*" mode="gen-user-scripts">
<!-- Start Code for Xiti Analytics -->
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/configuration-stat.js"></script>
<script type="text/javascript">
pageStatInjection();
</script>
<!-- End Code for Xiti Analytics -->
<!-- to customize: copy this to your override transform, add the content you want. -->
<!-- It will be placed before the ending HEAD tag -->
<!-- see (or enable) the named template "script-sample" for an example -->
</xsl:template>
Please note in the code above that I removed the two duplicate inclusions of configuration-stat.js because it is enough to include it only once.

In your initial request you said that you wanted to include also the scripts stat.js and stat-dpl.js but in your later code you did not include it as you did for configuration-stat.js. Do you still need stat.js and stat-dpl.js? If yes please include them in the same way as with configuration-stat.js.

After this modification please check if each HTML page generated by the Oxygen transformation contains the above <script> elements which include your JavaScript code in the Web page. After that you should check if your code is ever executed with some JavaScript debugging techniques. Do you have experience with running and debugging JavaScript code?


Regards,
Sorin
Minnu
Posts: 22
Joined: Fri Aug 28, 2009 11:39 am

Re: Adding analytic code

Post by Minnu »

Hi Sorin
I do not have experience with javascript debugging. Following your instructions, I tried running the script. But, in the ouput html file the script gets closed inside the .js. The script which I have given in the ditaimpl.xsl file is
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript">
pageStatInjection();
</script>
In the output html files, it is generated as:
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "/><script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "/><script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "/><script type="text/javascript">
pageStatInjection();
</script>
So, I was told that the .js file is not calling. Please help

Regards
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Adding analytic code

Post by sorin_ristache »

Hi,
Minnu wrote:in the ouput html file the script gets closed inside the .js.

. . .

So, I was told that the .js file is not calling.
I do not understand: do you mean that the JavaScript code ends unexpectedly, or that the JavaScript code is not called when it should be called?
Minnu wrote:The script which I have given in the ditaimpl.xsl file is
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript" src="http://designportal.apc.com/js/xiti/con ... "></script>
<script type="text/javascript">
pageStatInjection();
</script>
As I said above in this discussion you do not need to duplicate the inclusion of a JavaScript file. Why do you include configuration-stat.js 3 times in an HTML page?

Please see my previous post above where I suggested how you should include your JavaScript files in the output HTML pages. What are the JavaScript files that you need to include in the HTML pages? Did you test that JavaScript code in any way before including it in the HTML pages for making sure that it works correctly?

I do not know what your JavaScript code should do but: if the JavaScript code does not do what you want and you are not sure why then you will need to debug your JavaScript code to see where it does not work as expected. This is why you will need to work together with someone at your company who knows how to debug the JavaScript code for helping you to fix the code in your HTML pages.


Regards,
Sorin
Post Reply