ปลั๊กอิน Google Analytics สำหรับ Unity - การอ้างอิง API

เอกสารนี้จะอธิบายวิธีส่งข้อมูลและรายการเมธอด ทั้งหมดสำหรับปลั๊กอิน Google Analytics สำหรับ Unity

เกริ่นนำ

เมื่อส่งข้อมูลไปยัง Google Analytics โดยใช้ปลั๊กอิน GA สำหรับ Unity คุณสามารถใช้เมธอดพื้นฐานหรือเมธอด Builder คุณต้องใช้เมธอด Builder หากคุณต้องการเพิ่มพารามิเตอร์ของแคมเปญ หรือมิติข้อมูลหรือเมตริกที่กำหนดเองลงใน Hit คุณสามารถส่ง Hit โดยใช้วิธีใดก็ได้สลับกัน

ทำตามคู่มือสำหรับนักพัฒนาซอฟต์แวร์เพื่อตั้งค่าและกำหนดค่าปลั๊กอิน Google Analytics สำหรับ Unity สำหรับโปรเจ็กต์ของคุณ

ทั่วไป

จำนวน Hit ที่ได้รับ

ส่ง Hit (ข้อมูลพร็อพเพอร์ตี้ เหตุการณ์ ฯลฯ) ไปยัง Google Analytics หากมีการเชื่อมต่อเครือข่าย

public void DispatchHits();

แหล่งข้อมูลที่เกี่ยวข้อง

การควบคุมเซสชัน

เซสชันหมายถึงช่วงเวลาหนึ่งที่ผู้ใช้โต้ตอบกับเกม เซสชันทำหน้าที่เป็นคอนเทนเนอร์ที่มีประโยชน์ของกิจกรรมที่วัดได้ ซึ่งรวมถึงการดูหน้าจอ เหตุการณ์ และธุรกรรมอีคอมเมิร์ซ

คุณสามารถใช้วิธีการต่อไปนี้เพื่อบังคับให้เริ่มต้นหรือสิ้นสุดเซสชัน

// Start a new session.
public void StartSession();
// There should be no need to end a session explicitly. However, if you do
// need to indicate the end of session you can use the following method.
public void StopSession();

แหล่งข้อมูลที่เกี่ยวข้อง

หน้าจอ

หน้าจอใน Google Analytics แสดงถึงเนื้อหาที่ผู้ใช้กำลังดูภายในเกมของคุณ การดูหน้าจอประกอบด้วยช่องสตริงเดียวที่จะใช้เป็นชื่อหน้าจอในรายงาน Google Analytics

พื้นฐาน

public void LogScreen(string title);

ช่างก่อสร้าง

public void LogScreen(AppViewHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogScreen("Main Menu");

//Builder Hit with all App View parameters (all parameters required):
googleAnalytics.LogScreen(new AppViewHitBuilder()
    .SetScreenName("Main Menu"));

แหล่งข้อมูลที่เกี่ยวข้อง

กิจกรรม

เหตุการณ์เป็นวิธีที่มีประโยชน์ในการรวบรวมข้อมูลเกี่ยวกับการโต้ตอบของผู้ใช้กับองค์ประกอบแบบอินเทอร์แอกทีฟของเกม เช่น การใช้รายการหนึ่งๆ เหตุการณ์ประกอบด้วยช่อง 4 ช่องที่คุณสามารถใช้เพื่ออธิบายการโต้ตอบของผู้ใช้กับเกม

พื้นฐาน

public void LogEvent(string eventCategory,
    string eventAction,
    string eventLabel,
    long value);

ช่างก่อสร้าง

public void LogEvent(EventHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogEvent("Achievement", "Unlocked", "Slay 10 dragons", 5);

// Builder Hit with all Event parameters.
googleAnalytics.LogEvent(new EventHitBuilder()
    .SetEventCategory("Achievement")
    .SetEventAction("Unlocked")
    .SetEventLabel("Slay 10 dragons")
    .SetEventValue(5));

// Builder Hit with minimum required Event parameters.
googleAnalytics.LogEvent(new EventHitBuilder()
    .SetEventCategory("Achievement")
    .SetEventAction("Unlocked"));

แหล่งข้อมูลที่เกี่ยวข้อง

ข้อขัดข้องและข้อยกเว้น

การวัดข้อขัดข้องและข้อยกเว้นช่วยให้คุณวัดจำนวนและประเภทของข้อขัดข้องที่เจอและไม่พบ รวมถึงข้อยกเว้นที่เกิดขึ้นในเกม

พื้นฐาน

public void LogException(string exceptionDescription, bool isFatal);

ช่างก่อสร้าง

public void LogException(ExceptionHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogException("Incorrect input exception", true);

// Builder Hit with all Exception parameters.
googleAnalytics.LogException(new ExceptionHitBuilder()
    .SetExceptionDescription("Incorrect input exception")
    .SetFatal(true));

// Builder Hit with minimum required Exception parameters.
googleAnalytics.LogException(new ExceptionHitBuilder());

แหล่งข้อมูลที่เกี่ยวข้อง

ระยะเวลาของผู้ใช้

การวัดระยะเวลาของผู้ใช้เป็นวิธีดั้งเดิมในการวัดระยะเวลาใน Google Analytics ตัวอย่างเช่น วิธีนี้จะมีประโยชน์ในการวัดเวลาที่ใช้ในการโหลดทรัพยากร

พื้นฐาน

public void LogTiming(string timingCategory,
    long timingInterval,
    string timingName,
    string timingLabel);

ช่างก่อสร้าง

public void LogTiming(TimingHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogTiming("Loading", 50L, "Main Menu", "First Load");

// Builder Hit with all Timing parameters.
googleAnalytics.LogTiming(new TimingHitBuilder()
    .SetTimingCategory("Loading")
    .SetTimingInterval(50L)
    .SetTimingName("Main Menu")
    .SetTimingLabel("First load"));

// Builder Hit with minimum required Timing parameters.
googleAnalytics.LogTiming(new TimingHitBuilder()
    .SetTimingCategory("Loading")
    .SetTimingInterval(50L));

แหล่งข้อมูลที่เกี่ยวข้อง

การโต้ตอบในโซเชียล

การวัดการโต้ตอบทางโซเชียลช่วยให้คุณวัดการโต้ตอบของผู้ใช้กับการแชร์ผ่านโซเชียลเน็ตเวิร์กและวิดเจ็ตคำแนะนำต่างๆ ที่ฝังอยู่ในเนื้อหาได้

พื้นฐาน

public void LogSocial(string socialNetwork,
    string socialAction,
    string socialTarget);

ช่างก่อสร้าง

public void LogSocial(SocialHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogSocial("twitter", "retweet", "twitter.com/googleanalytics/status/482210840234295296");

// Builder Hit with all Social parameters.
googleAnalytics.LogSocial(new SocialHitBuilder()
    .SetSocialNetwork("Twitter")
    .SetSocialAction("Retweet")
    .SetSocialTarget("twitter.com/googleanalytics/status/482210840234295296"));

// Builder Hit with minimum required Social parameters.
googleAnalytics.LogSocial(new SocialHitBuilder()
    .SetSocialNetwork("Twitter")
    .SetSocialAction("Retweet"));

แหล่งข้อมูลที่เกี่ยวข้อง

อีคอมเมิร์ซ

การวัดอีคอมเมิร์ซช่วยให้คุณส่งการซื้อและการขายในเกมไปยัง Google Analytics ได้ ข้อมูลอีคอมเมิร์ซใน Google Analytics ประกอบด้วยรายการธุรกรรมและ Hit ของรายการ ซึ่งเกี่ยวข้องกันด้วยรหัสข้อมูลร่วม

ธุรกรรม

พื้นฐาน

public void LogTransaction(string transID,
    string affiliation,
    double revenue,
    double tax,
    double shipping);

public void LogTransaction(string transID,
    string affiliation,
    double revenue,
    double tax,
    double shipping,
    string currencyCode);

ช่างก่อสร้าง

public void LogTransaction(TransactionHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogTransaction("TRANS001", "Coin Store", 3.0, 0.0, 0.0);
googleAnalytics.LogTransaction("TRANS001", "Coin Store", 3.0, 0.0, 0.0, "USD");

// Builder Hit with all Transaction parameters.
googleAnalytics.LogTransaction(new TransactionHitBuilder()
    .SetTransactionID("TRANS001")
    .SetAffiliation("Coin Store")
    .SetRevenue(3.0)
    .SetTax(0)
    .SetShipping(0.0)
    .SetCurrencyCode("USD"));

// Builder Hit with minimum required Transaction parameters.
googleAnalytics.LogTransaction(new TransactionHitBuilder()
    .SetTransactionID("TRANS001")
    .SetAffiliation("Coin Store")
    .SetRevenue(3.0)
    .SetTax(0)
    .SetShipping(0.0));

รายการ

พื้นฐาน

public void LogItem(string transID,
    string name,
    string SKU,
    string category,
    double price,
    long quantity);

public void LogItem(string transID,
    string name,
    string SKU,
    string category,
    double price,
    long quantity,
    string currencyCode);

ช่างก่อสร้าง

public void LogItem(ItemHitBuilder builder);

ตัวอย่าง

googleAnalytics.LogItem("TRANS001", "Sword", "SWORD1223", "Weapon", 3.0, 2);
googleAnalytics.LogItem("TRANS001", "Sword", "SWORD1223", "Weapon", 3.0, 2, "USD");

// Builder Hit with all Item parameters.
googleAnalytics.LogItem(new ItemHitBuilder()
    .SetTransactionID("TRANS001")
    .SetName("Sword")
    .SetSKU("SWORD1223")
    .SetCategory("Weapon")
    .SetPrice(3.0)
    .SetQuantity(2)
    .SetCurrencyCode("USD"));

// Builder Hit with minimum required Item parameters.
googleAnalytics.LogItem(new ItemHitBuilder()
    .SetTransactionID("TRANS001")
    .SetName("Sword")
    .SetSKU("SWORD1223")
    .SetPrice(3.0)
    .SetQuantity(2));

แหล่งข้อมูลที่เกี่ยวข้อง

มิติข้อมูลและเมตริกที่กำหนดเอง

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

คุณต้องสร้างและกำหนดค่า มิติข้อมูลและเมตริกที่กำหนดเอง ก่อนที่จะใช้ เมื่อกำหนดค่าแล้ว คุณจะส่งข้อมูลเป็นส่วนหนึ่งของ Hit ได้โดยใช้เมธอด Builder

ช่างก่อสร้าง

// Custom Dimension.
public T SetCustomDimension(int dimensionNumber, string value);
// Custom Metric.
public T SetCustomMetric(int metricNumber, string value);

ตัวอย่าง

// Custom Dimension.
// An AppView hit example, but custom dimensions can be sent with all hit types.
googleAnalytics.LogScreen(new AppViewHitBuilder()
    .SetScreenName("Another screen")
    .SetCustomDimension(1, "200"));

// Custom Metric.
// An Event hit example, but custom metrics can be sent with all hit types.
googleAnalytics.LogEvent(new EventHitBuilder()
    .SetEventCategory("Achievement")
    .SetEventAction("Unlocked")
    .SetEventLabel("Slay 10 dragons")
    .SetEventValue(5)
    .SetCustomMetric(3, "200"));

แหล่งข้อมูลที่เกี่ยวข้อง

แคมเปญ

การวัดผลแคมเปญใน Google Analytics ช่วยให้คุณสามารถระบุแหล่งที่มาของแคมเปญและแหล่งที่มาของการเข้าชมไปยังกิจกรรมของผู้ใช้ภายในเกมได้

สามารถส่งพารามิเตอร์แคมเปญไปเป็นส่วนหนึ่งของ Hit โดยใช้เมธอด Builder

ช่างก่อสร้าง

public T SetCampaignName(string campaignName);
public T SetCampaignSource(string campaignSource);
public T SetCampaignMedium(string campaignMedium);
public T SetCampaignKeyword(string campaignKeyword);
public T SetCampaignContent(string campaignContent);
public T SetCampaignID(string campaignID);

ตัวอย่าง

googleAnalytics.LogTiming(new TimingHitBuilder()
    .SetTimingCategory("Loading")
    .SetTimingInterval(50L)
    .SetTimingName("Main Menu")
    .SetTimingLabel("First load")
    .SetCampaignName("Summer Campaign")
    .SetCampaignSource("google")
    .SetCampaignMedium("cpc")
    .SetCampaignKeyword("games")
    .SetCampaignContent("Free power ups")
    .SetCampaignId("Summer1"));

// Send campaign parameters with timing hit.
// Builder Hit with minimum required Campaign parameters.
googleAnalytics.LogTiming(new TimingHitBuilder()
    .SetTimingCategory("Loading")
    .SetTimingInterval(50L)
    .SetTimingName("Main Menu")
    .SetTimingLabel("First load")
    .SetCampaignSource("google");

แหล่งข้อมูลที่เกี่ยวข้อง

ระดับสูง

วิธีการเหล่านี้เหมาะสำหรับผู้ใช้ Google Analytics ขั้นสูงที่คุ้นเคยกับแนวคิดเครื่องมือติดตามเท่านั้น

SetOnTracker

กำหนดค่าในตัวติดตามที่จะส่งไปพร้อมกับ Hit อื่นๆ

ใช้ตัวแปรจาก Assets/Plugins/Fields.cs สำหรับพารามิเตอร์ fieldName (เช่น Fields.SCREEN_NAME)

public void SetOnTracker(Field fieldName, object value);

ตัวอย่าง

googleAnalytics.SetOnTracker(Fields.SCREEN_NAME, "Main Menu");

กำจัด

เพิ่มทรัพยากรที่มีการจัดการและรีเซ็ตตัวติดตาม

หากการกำจัดเรียกว่า Hit การติดตามถัดไปจะต้องสร้างตัวติดตามใหม่ ดังนั้นจึงขอแนะนำให้เรียกใช้วิธีนี้เมื่อการติดตามเสร็จสิ้นเท่านั้น ตัวอย่างเช่น ในเมธอด onDispose() ซึ่งจะทำงานเมื่อผู้ใช้ปิดเกม

public void Dispose();

ตัวอย่าง

googleAnalytics.Dispose();