为 Actionscript 2 实施 google 分析跟踪的最佳方法是什么?

发布于 2024-11-11 16:39:29 字数 196 浏览 4 评论 0原文

我正在寻找代码、示例、库、组件,以便在我的 Actionscript 2 Flash 电影中使用 Google Analytics 事件跟踪。我可以在 google code 网站上找到有关 AS3 的信息,但找不到 AS2 的信息。关于标记我的 Flash 文件以使用异步谷歌分析代码的教程和示例的最佳资源是什么。我发现了一些关于旧谷歌分析代码的旧信息。

谢谢

I am looking for code, examples, library, components for using google analytics event tracking with my Actionscript 2 Flash movies. I can find info about AS3 on the google code site but not AS2. What is the best resource for tutorials and examples about tagging my Flash files to use the asynch google analytics code. I have found some old information about the old google analytics code.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不乱于心 2024-11-18 16:39:29

我必须对 AS2 项目进行大量维护,所以我知道你来自哪里。我的做法如下:

第 1 步是在 HTML 中设置一个可供 Flash 电影使用的 google 分析跟踪信标。 Google 有如何执行此操作的示例,但这里是我最近所做的设置示例:

<!-- Set up Google Analytics tracking -->
    <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">

        // I'm pulling in my project id tag from a config file
        // you will want to use the project id that google gives you. Ex: UA-#####-#

        var pageTracker = _gat._getTracker('<?php echo $config['_tracker']; ?>');
        pageTracker._initData();

    </script>
<!-- End Google Analytics setup -->

在页面上设置信标后,您现在可以使用ExternalInterface 让 Flash 影片向 google 发送跟踪消息。在 Flash 的某个地方,您需要一个可以从代码中的其他位置调用的函数,如下所示:

function track(event:String) {    
    if(ExternalInterface.available) {
        ExternalInterface.call("pageTracker._trackPageview", event);
    }
}

当您想要跟踪事件时,您可以传入一个使用 google Analytics 语法准确描述该事件的字符串。例如:/root/loadingFinished 或类似的内容。

希望这有帮助!祝你好运!

I've had to do a lot of mainenance on AS2 projects, so I know where you're coming from. Here's what I do:

Step 1 is to get a google analytics tracking beacon set up in your HTML that your flash movie can use. Google has examples of how to do this, but here's an example of a set up that I did recently:

<!-- Set up Google Analytics tracking -->
    <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">

        // I'm pulling in my project id tag from a config file
        // you will want to use the project id that google gives you. Ex: UA-#####-#

        var pageTracker = _gat._getTracker('<?php echo $config['_tracker']; ?>');
        pageTracker._initData();

    </script>
<!-- End Google Analytics setup -->

With the beacon set up on your page, you can now use ExternalInterface to have your flash movie send tracking messages to google. Somewhere in your flash you'll need a function that you can call up from anywhere else in your code that looks like this:

function track(event:String) {    
    if(ExternalInterface.available) {
        ExternalInterface.call("pageTracker._trackPageview", event);
    }
}

When you want to track an event, you pass in a string that accurately describes the event using google analytics syntax. Ex: /root/loadingFinished or something similar.

Hopefully this helps! Good luck!

另类 2024-11-18 16:39:29

我已将其添加到我的 Flash 项目中,到目前为止似乎可以正常工作。我还没有留下足够长的时间来检查谷歌分析报告中的情况,但我将用所发生的情况更新这个答案。

import flash.external.ExternalInterface;
//
function ga_track_pageview(_event:String) {
     if(ExternalInterface.available) {
        ExternalInterface.call("_gaq.push",['_trackPageview', _event]);
    }   
}
function ga_track_event(_category:String, _action:String, _label:String, _value:Number) {
     if(ExternalInterface.available) {
        ExternalInterface.call("_gaq.push",['_trackEvent', _category, _action, _label, _value]);
    }   
}
//
// Button 1 pressed - 
btn_1.onRelease = function() {
    _root.ga_track_event("button", "pressed", "button1", null);
}
// Button 2 pressed - 
btn_2.onRelease = function() {
    _root.ga_track_event("button", "pressed", "button2", null);
}
// Tracking a page view -
ga_track_pageview("testpage_opened");

I have added this to my Flash projects and it seems to work so far. I have not left it long enough to check what has come through on google analytics reports yet but I will update this answer with what comes through.

import flash.external.ExternalInterface;
//
function ga_track_pageview(_event:String) {
     if(ExternalInterface.available) {
        ExternalInterface.call("_gaq.push",['_trackPageview', _event]);
    }   
}
function ga_track_event(_category:String, _action:String, _label:String, _value:Number) {
     if(ExternalInterface.available) {
        ExternalInterface.call("_gaq.push",['_trackEvent', _category, _action, _label, _value]);
    }   
}
//
// Button 1 pressed - 
btn_1.onRelease = function() {
    _root.ga_track_event("button", "pressed", "button1", null);
}
// Button 2 pressed - 
btn_2.onRelease = function() {
    _root.ga_track_event("button", "pressed", "button2", null);
}
// Tracking a page view -
ga_track_pageview("testpage_opened");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文