示例#1
0
    public function testTrackPageView()
    {
        $viewer = CMTest_TH::createUser();
        $environment = new CM_Frontend_Environment(CM_Site_Abstract::factory(), $viewer);
        $client = new CMService_AdWords_Client();
        $pushConversion = new ReflectionMethod($client, '_pushConversion');
        $pushConversion->setAccessible(true);
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}}'));
        $pushConversion->invoke($client, $viewer, CMService_AdWords_Conversion::fromJson('{"google_conversion_id":789}'));
        $this->assertSame('', $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
EOD
, $client->getHtml($environment));
        $client->trackPageView($environment, '/');
        $this->assertSame(<<<EOD
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
EOD
, $client->getJs());
        $this->assertSame(<<<EOD
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script><script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({"google_conversion_id":123456,"google_conversion_language":"en","google_conversion_format":"1","google_conversion_color":"666666","google_conversion_label":"label","google_remarketing_only":true,"google_conversion_value":123,"google_conversion_currency":"USD","google_custom_params":{"a":1,"b":2}});window.google_trackConversion({"google_conversion_id":789});
//]]>
</script>
EOD
, $client->getHtml($environment));
    }
示例#2
0
文件: Client.php 项目: cargomedia/cm
 /**
  * @param CM_Model_User $user
  */
 protected function _flushTrackingQueue(CM_Model_User $user)
 {
     while ($trackingData = $this->_popTrackingData($user)) {
         $conversion = CMService_AdWords_Conversion::fromJson($trackingData['conversion']);
         $this->_addConversion($conversion);
     }
 }
示例#3
0
    public function testFromJson()
    {
        $conversion = CMService_AdWords_Conversion::fromJson('{}');
        $this->assertSame(null, $conversion->getId());
        $this->assertSame(null, $conversion->getLanguage());
        $this->assertSame(null, $conversion->getFormat());
        $this->assertSame(null, $conversion->getColor());
        $this->assertSame(null, $conversion->getLabel());
        $this->assertSame(null, $conversion->getRemarketingOnly());
        $this->assertSame(null, $conversion->getConversionValue());
        $this->assertSame(null, $conversion->getConversionCurrency());
        $this->assertSame(null, $conversion->getCustomParameterList());
        $conversion = CMService_AdWords_Conversion::fromJson(<<<EOD
{
    "google_conversion_id": 123456,
    "google_conversion_language": "en",
    "google_conversion_format": "1",
    "google_conversion_color": "666666",
    "google_conversion_label": "label",
    "google_remarketing_only": true,
    "google_conversion_value": 123,
    "google_conversion_currency": "USD",
    "google_custom_params": {
        "a": 1,
        "b": 2
    }
}
EOD
);
        $this->assertSame(123456, $conversion->getId());
        $this->assertSame('en', $conversion->getLanguage());
        $this->assertSame('1', $conversion->getFormat());
        $this->assertSame('666666', $conversion->getColor());
        $this->assertSame('label', $conversion->getLabel());
        $this->assertSame(true, $conversion->getRemarketingOnly());
        $this->assertSame(123.0, $conversion->getConversionValue());
        $this->assertSame('USD', $conversion->getConversionCurrency());
        $this->assertSame(['a' => 1, 'b' => 2], $conversion->getCustomParameterList());
    }