รหัสผู้ใช้ - iOS SDK

คู่มือนักพัฒนาซอฟต์แวร์นี้อธิบายวิธีติดตั้งใช้งาน User ID โดยใช้ Google Analytics SDK สำหรับ iOS v3.x

ภาพรวม

ฟีเจอร์ User-ID ช่วยวัดกิจกรรมผู้ใช้ที่ครอบคลุมหลายอุปกรณ์ใน Google Analytics เช่น การระบุแหล่งที่มาของการโต้ตอบกับแคมเปญการตลาดในอุปกรณ์เคลื่อนที่เครื่องหนึ่งต่อ Conversion ที่เกิดขึ้นในอุปกรณ์เคลื่อนที่อีกเครื่องหนึ่งหรือในเบราว์เซอร์

เมื่อมีการส่ง User ID พร้อม Hit ของ Google Analytics โดยใช้ช่อง userId รายงานของคุณจะแสดงจำนวนผู้ใช้ที่ไม่ซ้ำที่ถูกต้องแม่นยำยิ่งขึ้น และนำเสนอตัวเลือกการรายงานจากหลายอุปกรณ์ใหม่ๆ ดูข้อมูลเพิ่มเติมเกี่ยวกับประโยชน์ของการใช้ User ID

คู่มือนี้จะแสดงวิธีใช้ช่อง userId และ Google Analytics SDK สำหรับ iOS เพื่อส่ง User-ID ไปยัง Google Analytics

ข้อกำหนดเบื้องต้น

ก่อนที่จะส่ง User ID ไปยัง Google Analytics:

การใช้งาน

เมื่อทราบว่าแอปพลิเคชัน iOS ของคุณเป็นผู้ใช้ คุณควรส่งรหัสที่แสดงถึงผู้ใช้ดังกล่าวพร้อม Hit ของ Google Analytics ทั้งหมด เช่น การดูหน้าเว็บ เหตุการณ์ ธุรกรรมอีคอมเมิร์ซ ฯลฯ โดยใช้ช่อง userId

หากต้องการส่ง User-ID ให้ตั้งค่าช่อง userId โดยใช้ ไวยากรณ์แอมเพอร์แซนด์ของ Measurement Protocol และชื่อพารามิเตอร์ kGAIUserId ตามที่แสดงในตัวอย่างนี้

/**
 * An example method called when a user signs in to an authentication system.
 *
 * @param user represents a generic User object returned by an authentication system on sign in.
 */
- void signInWithUser:(User *)user {

  id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

  // You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
  // sent with all subsequent hits.
  [tracker set:kGAIUserId
         value:user.id];

  // This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
  [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"UX"            // Event category (required)
                                                        action:@"User Sign In"  // Event action (required)
                                                         label:nil              // Event label
                                                         value:nil] build]];    // Event value
}

ตัวอย่างนี้แสดงวิธีขอรับ User ID

NSString *userId = [tracker get:kGAIUserId];