كود HTML:
<html> <?php include ("header.php"); ?> <body> <?php include ("sideNav.php"); ?> <?php include ("main.php"); ?> <?php include ("analyticsTracking.php"); ?> </body> </html>
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? The Google Analytics tracking code is now the same for both secure and non-secure websites. The new tracking code detects the protocol of the page being tracked and matches the security of your web page automatically. Pages with URLs beginning with
http:// will download the non-secure version at
http://www.google-analytics.com/ga.js and pages with URLs beginning with
https:// will load the secure version at
https://ssl.google-analytics.com/ga.js. No modification of the tracking code on secure pages is required.
Although the previous version of the tracking code (
urchin.js) required you to copy/paste special tracking code into your secure pages, this is no longer necessary if you are tracking your site with
ga.js. You can use the same tracking code on both secure (
https://) and non-secure (
http://) pages.
The new tracking code looks like this:
كود PHP:
<script type="text/javascript">
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"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>
Installing the GA tracking code on a site that uses frames requires some careful consideration to ensure that your traffic is tracked accurately, and that the referral information is retained.
- Where should I place my tracking code?
- Why isn't my CPC information appearing?
- Why aren't referrals showing up?
- Is my traffic being inflated?
1. Where should I place my tracking code? We recommend that a site which uses frames include the tracking code in the
<head> section of the frameset page, as well as directly before the
</body> tag of each child frame that you want to track. (The tracking code goes into the head section of the frameset page, as these documents don't contain a body section.) If you place your tracking code within a
<noframe> tag thinking that it's equivalent to the body, the code will not run and no data will be recorded.
2. Why isn't my CPC information appearing even though I've enabled auto-tagging? The landing page URL of your ads is the frameset document, not the child frames within that document. If you haven't added tracking code to the
<head> section of your frameset, Analytics won't track that page and your campaign parameters will be lost.
3. Why aren't referrals showing up? If all frames on the site reside on the same domain, then referral information can be properly recorded as long as you've installed the tracking code on the first page users visit on the site. If frames on the site reside on different domains, the referral information is likely to be inaccurate, since one frame may be recorded as the referring source of another, instead of a previous site being recorded as the referring source.
In either case, the
Navigation Summary and
Site Overlay reports for sites with frames is not likely to provide useful information, since every frame with tracking code on it will be recorded as a separate pageview. Additionally, the order of these pageviews will depend on the order in which the frames are loaded instead of the actual navigation path taken by your visitors.
4. Is my traffic being inflated? Users may experience what they consider to be inflated traffic since every framed page, as well as the frameset, will be tracked individually. For example, if a frameset with tracking code has three frames, with tracking code installed in each frame, a single visit to the frameset URL will result in four pageviews. Users may choose to track only some of the framed pages, or only the frameset itself. Your implementation will depend on what data you're interested in collecting.
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? By using the
_trackPageviewfunction, you can assign a page filename to any Javascript event.
Important:
if your pages include a call to _trackPageview, _setAllowLinker _trackTrans(), your Analytics tracking code must be placed in your HTML code above any of these calls. In these cases the tracking code can be placed anywhere between the opening <body> tag and the JavaScript call. To track an event, call
_trackPageview() with an argument specifying a name for the event. For example:
pageTracker._trackPageview("/homepage/link1"); will cause each occurrence of the calling event to be logged as though it were a pageview for the URL
/homepage/link1 . The argument must begin with a forward slash and be in quotes. The event names may be organized into any directory style structure you wish.
For example, if you wish to organize events by page > type of event, you might organize a hierarchy along these lines:
- '/homepage/links/link1'
- '/homepage/radiobuttons/button1'
- '/contactform/rollovers/image1'
HTML Code Examples The following illustrates how to log an onClick event:
كود HTML:
<a href="javascript:void(0);"onClick="javascript:pageTracker._trackPageview('/folder/file');" >Or, to log a rollover event:
كود HTML:
<a href="javascript:void(0);" onMouseOver="javascript:pageTracker._trackPageview('/folder/file');" >To verify that
pageTracker is being called correctly, you can check your
Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? Google Analytics provides an easy way to track clicks on links that lead to file downloads. Because these links do not lead to a page on your site containing the tracking code, you'll need to tag the link itself with the
_trackPageview() JavaScript if you would like to track these downloads. This piece of JavaScript assigns a pageview to any click on a link - the pageview is attributed to the filename you specify.
For example, to log every click on a particular link to
www.example.com/files/map.pdf as a pageview for
/downloads/map you would add the following attribute to the link's
<a> tag:
كود HTML:
<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('/downloads/map'); "> Important:
if your pages include a call to _trackPageview, _setAllowLinker _trackTrans(), your Analytics tracking code must be placed in your HTML code above any of these calls. In these cases the tracking code can be placed anywhere between the opening <body> tag and the JavaScript call. To verify that _trackPageviewis being called correctly, you can check your
Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? Google Analytics provides an easy way to track clicks on links that lead away from your site. Because these links do not lead to a page on your site containing the UTM JavaScript, you will need to tag the link itself. This piece of JavaScript assigns a pageview to any click on a link - the pageview is attributed to the filename you specify.
For example, to log every click on a particular link to
www.example.com as a pageview for "
/outgoing/example_com" you would add the following attribute to the link's tag:
كود HTML:
<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">It is a good idea to log all of your outbound links into a logical directory structure as shown in the example. This way, you will be able to easily identify what pages visitors clicked on to leave your site.
Important:
if your pages include a call to _trackPageview, _setAllowLinker _trackTrans(), your Analytics tracking code must be placed in your HTML code above any of these calls. In these cases the tracking code can be placed anywhere between the opening <body> tag and the JavaScript call. To verify that _trackPageviewis being called correctly, you can check your
Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? (If you're looking for information on tracking visitor movement through your checkout pages, please read
How do I use Google Analytics to track a 3rd-party shopping cart?)
Enabling E-Commerce Reporting in the Profile
The first step of tracking e-commerce transactions is to enable e-commerce reporting for your website's profile. To enable e-commerce reporting, please follow these steps:
- Log in to your account.
- Click Edit next to the profile you'd like to enable.
- On the Profile Settings page, click edit next to Main Website Profile Information.
- Change the E-Commerce Website radio button from No to Yes.
Receipt Page Format
The second step is to ensure that the tracking code is included in the receipt page in the standard fashion. This may be done using a server side include, or other template driver, or can simply be hand-coded into your HTML code:
كود HTML:
<script type="text/javascript">
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"));
</script> <script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script> Next, somewhere in the receipt below the tracking code, call the _addTrans() and _addItem() functions. Begin with a call to _addTrans() to establish a transaction. _addTrans() takes the following arguments: Order ID,Affiliation, Total, Tax, Shipping, City, State, Country. For each item that the visitor purchases, call _addItem(). _addItem() takes the following arguments: Order ID, SKU or Code, Product Name, Category, Price, Quantity.
Here is a complete example:
كود HTML:
<script type="text/javascript">
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"));
</script> <script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._initData();
pageTracker._trackPageview();
pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"11.99", // Total
"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);
pageTracker._addItem(
"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
);
pageTracker._trackTrans();
</script>
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? Google Analytics lets you track any browser based event, including Flash and JavaScript events by using the
_trackPageview function, you can assign a page filename to any Flash action, and enter that filename into the appropriate goal or funnel step. Important: Please note that your analytics tracking code and calls to
_gat._getTracker and
_initData must be placed on the page above the call to
_trackPageview. كود HTML:
<script type="text/javascript">
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"));
</script> <script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>To track an event, call
_trackPageview() with an argument specifying a name for the event. For example, calling:
pageTracker._trackPageview("/purchase_funnel/page1.html");
will cause each occurrence of the the calling Flash event to be logged as though it were a pageview under the name
/purchase_funnel/page1.html . The argument must begin with a forward slash and be in quotes. The event names may be organized into any directory style structure you wish. The path/filename argument to
_trackPageview need not represent an actual URL on your website.
Flash Code Examples
كود HTML:
on (release) {
// Track with no action
getURL("javascript:pageTracker._trackPageview('/folder/file.html');");
}
on (release) {
//Track with action
getURL("javascript:pageTracker._trackPageview('/folder/file.html');");
_root.gotoAndPlay(3);
myVar = "Flash Track Test";
}
onClipEvent (enterFrame) {
getURL("javascript:pageTracker._trackPageview('/folder/file.html');");
}To verify that
_trackPageview is being called correctly, you can check your Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.
Note: This article is for the latest version of the tracking code. If you are using the older version, please read the following
article.
To determine which tracking code you are using, please see
Which version of the tracking code am I using? To add the tracking code to your ASP site, add the following line to each template page for your site before the closing tag: <!--#include file="analytics.asp"--> Then, upload a file called analytics.asp to your site. This file should contain your tracking code:
كود HTML:
<script type="text/javascript">
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"));
</script> <script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>
مواقع النشر (المفضلة)