Difference between revisions of "Tracking Links (JavaScript)"

From Market Ruler Help
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
The '''cr_link''' function is a [[JavaScript]] function which enables you to track when visitors to your web site click on specific links.
+
The '''__CR.link''' function is a [[JavaScript]] function which enables you to track when visitors to your web site click on specific links.
  
 
== Simple implementation ==
 
== Simple implementation ==
The syntax for using '''cr_link''' in a link is as follows:
+
The syntax for using '''__CR.link''' in a link is as follows:
  
 
'''Before:'''
 
'''Before:'''
 
<pre><a href="Company-Brochure.pdf">Download our company brochure now!</a></pre>
 
<pre><a href="Company-Brochure.pdf">Download our company brochure now!</a></pre>
 
'''After:'''
 
'''After:'''
<pre><a href="Company-Brochure.pdf" onclick="return (typeof cr_link != 'undefined') ? cr_link(this, 4) : true">Download our company brochure now!</a></pre>
+
<pre><a href="Company-Brochure.pdf" onclick="return window.__CR ? __CR.link(this, 4) : true">Download our company brochure now!</a></pre>
  
 
Specifically, you will add an [[JavaScript onclick]] handler to your link to invoke our tracking prior to the user clicking the link.
 
Specifically, you will add an [[JavaScript onclick]] handler to your link to invoke our tracking prior to the user clicking the link.
Line 15: Line 15:
 
Note that the [[Action Code]] (in this case, "4") will change for different actions.
 
Note that the [[Action Code]] (in this case, "4") will change for different actions.
  
Finally, note that you need to [[Install the Tracking Snippet]] on each page where you use '''cr_link''' for the above code to work.
+
Finally, note that you need to [[Install the Tracking Snippet]] on each page where you use '''__CR.link''' for the above code to work.
  
 
== Advanced implementation ==
 
== Advanced implementation ==
Line 23: Line 23:
 
<pre><a href="Company-Brochure.pdf" onclick="link_to_download()">Download our company brochure now!</a></pre>
 
<pre><a href="Company-Brochure.pdf" onclick="link_to_download()">Download our company brochure now!</a></pre>
 
'''After:'''
 
'''After:'''
<pre><a href="Company-Brochure.pdf" onclick="link_to_download(); return (typeof cr_link != 'undefined') ? cr_link(this, 4) : true">Download our company brochure now!</a></pre>
+
<pre><a href="Company-Brochure.pdf" onclick="link_to_download(); return window.__CR ? __CR.link(this, 4) : true">Download our company brochure now!</a></pre>
  
 
The above solution may change on a case-by-case basis. If you are ever in need of assistance, please contact [[ConversionRuler Support]].
 
The above solution may change on a case-by-case basis. If you are ever in need of assistance, please contact [[ConversionRuler Support]].
Line 29: Line 29:
 
As always, there are [http://conversion.marketruler.com/setup/codegen.php tools in '''ConversionRuler'''] to help you do this.  
 
As always, there are [http://conversion.marketruler.com/setup/codegen.php tools in '''ConversionRuler'''] to help you do this.  
  
== See also ===
+
== Deprecated Functionality: cr_link ==
 +
The '''__CR.link''' function was previously called '''cr_link''' and has since been renamed. The '''cr_link''' call will be supported until its use is no longer detected.
 +
 
 +
== See also ==
 +
 
 
* [http://conversion.marketruler.com/setup/codegen.php ConversionRuler Code Generator]
 
* [http://conversion.marketruler.com/setup/codegen.php ConversionRuler Code Generator]
 
* [[JavaScript]]
 
* [[JavaScript]]
 
* [[JavaScript onclick]]
 
* [[JavaScript onclick]]
 +
* [[Tracking Links (JavaScript)]]
 +
* [[__CR.track|__CR.track]]
 +
* [[__CR.submit|__CR.submit]]
 +
* [[When to use __CR.submit, __CR.link, and __CR.track]]
  
 
[[Category:ConversionRuler]]
 
[[Category:ConversionRuler]]
 +
[[Category:Technical]]
 
[[Category:ConversionRuler JavaScript Functions]]
 
[[Category:ConversionRuler JavaScript Functions]]
[[Category:Technical]]
+
[[Category:ConversionRuler Installation]]
[[Category:Snippet]]
 

Latest revision as of 23:30, 29 January 2021

The __CR.link function is a JavaScript function which enables you to track when visitors to your web site click on specific links.

Simple implementation

The syntax for using __CR.link in a link is as follows:

Before:

<a href="Company-Brochure.pdf">Download our company brochure now!</a>

After:

<a href="Company-Brochure.pdf" onclick="return window.__CR ? __CR.link(this, 4) : true">Download our company brochure now!</a>

Specifically, you will add an JavaScript onclick handler to your link to invoke our tracking prior to the user clicking the link.

Add this code to any link you wish to track. As well, you will likely need to create a Conversion Action to assign to each type of link you want to track.

Note that the Action Code (in this case, "4") will change for different actions.

Finally, note that you need to Install the Tracking Snippet on each page where you use __CR.link for the above code to work.

Advanced implementation

If you want to track a link which already has the onclick attribute in use, then you'll need to modify how you invoke it:

Before:

<a href="Company-Brochure.pdf" onclick="link_to_download()">Download our company brochure now!</a>

After:

<a href="Company-Brochure.pdf" onclick="link_to_download(); return window.__CR ? __CR.link(this, 4) : true">Download our company brochure now!</a>

The above solution may change on a case-by-case basis. If you are ever in need of assistance, please contact ConversionRuler Support.

As always, there are tools in ConversionRuler to help you do this.

Deprecated Functionality: cr_link

The __CR.link function was previously called cr_link and has since been renamed. The cr_link call will be supported until its use is no longer detected.

See also